mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-12 10:30:28 +00:00
(svn r23214) -Codechange: for base media sets pass the "search in tars" parameter to determine what to do
This commit is contained in:
parent
a06443774f
commit
15f671279d
@ -40,17 +40,17 @@ struct MD5File {
|
|||||||
* Information about a single base set.
|
* Information about a single base set.
|
||||||
* @tparam T the real class we're going to be
|
* @tparam T the real class we're going to be
|
||||||
* @tparam Tnum_files the number of files in the set
|
* @tparam Tnum_files the number of files in the set
|
||||||
* @tparam Tsubdir the subdirectory where to find the files
|
* @tparam Tsearch_in_tars whether to search in the tars or not
|
||||||
*/
|
*/
|
||||||
template <class T, size_t Tnum_files, Subdirectory Tsubdir>
|
template <class T, size_t Tnum_files, bool Tsearch_in_tars>
|
||||||
struct BaseSet {
|
struct BaseSet {
|
||||||
typedef SmallMap<const char *, const char *> TranslatedStrings;
|
typedef SmallMap<const char *, const char *> TranslatedStrings;
|
||||||
|
|
||||||
/** Number of files in this set */
|
/** Number of files in this set */
|
||||||
static const size_t NUM_FILES = Tnum_files;
|
static const size_t NUM_FILES = Tnum_files;
|
||||||
|
|
||||||
/** The sub directory to search for the files */
|
/** Whether to search in the tars or not. */
|
||||||
static const Subdirectory SUBDIR = Tsubdir;
|
static const bool SEARCH_IN_TARS = Tsearch_in_tars;
|
||||||
|
|
||||||
/** Internal names of the files in this set. */
|
/** Internal names of the files in this set. */
|
||||||
static const char * const *file_names;
|
static const char * const *file_names;
|
||||||
@ -164,9 +164,8 @@ public:
|
|||||||
static uint FindSets()
|
static uint FindSets()
|
||||||
{
|
{
|
||||||
BaseMedia<Tbase_set> fs;
|
BaseMedia<Tbase_set> fs;
|
||||||
/* GM_DIR == music set. Music sets don't support tars,
|
/* Searching in tars is only done in the sound and graphics base sets. */
|
||||||
* so there is no need to search for tars in that case. */
|
return fs.Scan(GetExtension(), Tbase_set::SEARCH_IN_TARS ? BASESET_DIR : GM_DIR, Tbase_set::SEARCH_IN_TARS);
|
||||||
return fs.Scan(GetExtension(), Tbase_set::SUBDIR, Tbase_set::SUBDIR != GM_DIR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool SetSet(const char *name);
|
static bool SetSet(const char *name);
|
||||||
@ -204,7 +203,7 @@ enum BlitterType {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/** All data of a graphics set. */
|
/** All data of a graphics set. */
|
||||||
struct GraphicsSet : BaseSet<GraphicsSet, MAX_GFT, BASESET_DIR> {
|
struct GraphicsSet : BaseSet<GraphicsSet, MAX_GFT, true> {
|
||||||
PaletteType palette; ///< Palette of this graphics set
|
PaletteType palette; ///< Palette of this graphics set
|
||||||
BlitterType blitter; ///< Blitter of this graphics set
|
BlitterType blitter; ///< Blitter of this graphics set
|
||||||
|
|
||||||
@ -217,7 +216,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
/** All data of a sounds set. */
|
/** All data of a sounds set. */
|
||||||
struct SoundsSet : BaseSet<SoundsSet, 1, BASESET_DIR> {
|
struct SoundsSet : BaseSet<SoundsSet, 1, true> {
|
||||||
};
|
};
|
||||||
|
|
||||||
/** All data/functions related with replacing the base sounds */
|
/** All data/functions related with replacing the base sounds */
|
||||||
@ -236,7 +235,7 @@ static const uint NUM_SONGS_AVAILABLE = 1 + NUM_SONG_CLASSES * NUM_SONGS_CLASS;
|
|||||||
static const uint NUM_SONGS_PLAYLIST = 32;
|
static const uint NUM_SONGS_PLAYLIST = 32;
|
||||||
|
|
||||||
/** All data of a music set. */
|
/** All data of a music set. */
|
||||||
struct MusicSet : BaseSet<MusicSet, NUM_SONGS_AVAILABLE, GM_DIR> {
|
struct MusicSet : BaseSet<MusicSet, NUM_SONGS_AVAILABLE, false> {
|
||||||
/** The name of the different songs. */
|
/** The name of the different songs. */
|
||||||
char song_name[NUM_SONGS_AVAILABLE][32];
|
char song_name[NUM_SONGS_AVAILABLE][32];
|
||||||
byte track_nr[NUM_SONGS_AVAILABLE];
|
byte track_nr[NUM_SONGS_AVAILABLE];
|
||||||
|
@ -39,8 +39,8 @@ template <class Tbase_set> /* static */ Tbase_set *BaseMedia<Tbase_set>::duplica
|
|||||||
* @param allow_empty_filename empty filenames are valid
|
* @param allow_empty_filename empty filenames are valid
|
||||||
* @return true if loading was successful.
|
* @return true if loading was successful.
|
||||||
*/
|
*/
|
||||||
template <class T, size_t Tnum_files, Subdirectory Tsubdir>
|
template <class T, size_t Tnum_files, bool Tsearch_in_tars>
|
||||||
bool BaseSet<T, Tnum_files, Tsubdir>::FillSetDetails(IniFile *ini, const char *path, const char *full_filename, bool allow_empty_filename)
|
bool BaseSet<T, Tnum_files, Tsearch_in_tars>::FillSetDetails(IniFile *ini, const char *path, const char *full_filename, bool allow_empty_filename)
|
||||||
{
|
{
|
||||||
memset(this, 0, sizeof(*this));
|
memset(this, 0, sizeof(*this));
|
||||||
|
|
||||||
@ -78,9 +78,9 @@ bool BaseSet<T, Tnum_files, Tsubdir>::FillSetDetails(IniFile *ini, const char *p
|
|||||||
for (uint i = 0; i < Tnum_files; i++) {
|
for (uint i = 0; i < Tnum_files; i++) {
|
||||||
MD5File *file = &this->files[i];
|
MD5File *file = &this->files[i];
|
||||||
/* Find the filename first. */
|
/* Find the filename first. */
|
||||||
item = files->GetItem(BaseSet<T, Tnum_files, Tsubdir>::file_names[i], false);
|
item = files->GetItem(BaseSet<T, Tnum_files, Tsearch_in_tars>::file_names[i], false);
|
||||||
if (item == NULL || (item->value == NULL && !allow_empty_filename)) {
|
if (item == NULL || (item->value == NULL && !allow_empty_filename)) {
|
||||||
DEBUG(grf, 0, "No " SET_TYPE " file for: %s (in %s)", BaseSet<T, Tnum_files, Tsubdir>::file_names[i], full_filename);
|
DEBUG(grf, 0, "No " SET_TYPE " file for: %s (in %s)", BaseSet<T, Tnum_files, Tsearch_in_tars>::file_names[i], full_filename);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,7 +131,7 @@ bool BaseSet<T, Tnum_files, Tsubdir>::FillSetDetails(IniFile *ini, const char *p
|
|||||||
file->missing_warning = strdup(item->value);
|
file->missing_warning = strdup(item->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (file->CheckMD5(Tsubdir)) {
|
switch (file->CheckMD5(Tsearch_in_tars ? BASESET_DIR : GM_DIR)) {
|
||||||
case MD5File::CR_MATCH:
|
case MD5File::CR_MATCH:
|
||||||
this->valid_files++;
|
this->valid_files++;
|
||||||
/* FALL THROUGH */
|
/* FALL THROUGH */
|
||||||
@ -155,7 +155,7 @@ bool BaseMedia<Tbase_set>::AddFile(const char *filename, size_t basepath_length,
|
|||||||
|
|
||||||
Tbase_set *set = new Tbase_set();
|
Tbase_set *set = new Tbase_set();
|
||||||
IniFile *ini = new IniFile();
|
IniFile *ini = new IniFile();
|
||||||
ini->LoadFromDisk(filename, Tbase_set::SUBDIR);
|
ini->LoadFromDisk(filename, Tbase_set::SEARCH_IN_TARS ? BASESET_DIR : GM_DIR);
|
||||||
|
|
||||||
char *path = strdup(filename + basepath_length);
|
char *path = strdup(filename + basepath_length);
|
||||||
char *psep = strrchr(path, PATHSEPCHAR);
|
char *psep = strrchr(path, PATHSEPCHAR);
|
||||||
|
@ -248,7 +248,7 @@ void GfxLoadSprites()
|
|||||||
|
|
||||||
bool GraphicsSet::FillSetDetails(IniFile *ini, const char *path, const char *full_filename)
|
bool GraphicsSet::FillSetDetails(IniFile *ini, const char *path, const char *full_filename)
|
||||||
{
|
{
|
||||||
bool ret = this->BaseSet<GraphicsSet, MAX_GFT, BASESET_DIR>::FillSetDetails(ini, path, full_filename, false);
|
bool ret = this->BaseSet<GraphicsSet, MAX_GFT, true>::FillSetDetails(ini, path, full_filename, false);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
IniGroup *metadata = ini->GetGroup("metadata");
|
IniGroup *metadata = ini->GetGroup("metadata");
|
||||||
IniItem *item;
|
IniItem *item;
|
||||||
@ -299,8 +299,8 @@ MD5File::ChecksumResult MD5File::CheckMD5(Subdirectory subdir) const
|
|||||||
static const char * const _graphics_file_names[] = { "base", "logos", "arctic", "tropical", "toyland", "extra" };
|
static const char * const _graphics_file_names[] = { "base", "logos", "arctic", "tropical", "toyland", "extra" };
|
||||||
|
|
||||||
/** Implementation */
|
/** Implementation */
|
||||||
template <class T, size_t Tnum_files, Subdirectory Tsubdir>
|
template <class T, size_t Tnum_files, bool Tsearch_in_tars>
|
||||||
/* static */ const char * const *BaseSet<T, Tnum_files, Tsubdir>::file_names = _graphics_file_names;
|
/* static */ const char * const *BaseSet<T, Tnum_files, Tsearch_in_tars>::file_names = _graphics_file_names;
|
||||||
|
|
||||||
template <class Tbase_set>
|
template <class Tbase_set>
|
||||||
/* static */ bool BaseMedia<Tbase_set>::DetermineBestSet()
|
/* static */ bool BaseMedia<Tbase_set>::DetermineBestSet()
|
||||||
|
@ -27,8 +27,8 @@ static const char * const _music_file_names[] = {
|
|||||||
/** Make sure we aren't messing things up. */
|
/** Make sure we aren't messing things up. */
|
||||||
assert_compile(lengthof(_music_file_names) == NUM_SONGS_AVAILABLE);
|
assert_compile(lengthof(_music_file_names) == NUM_SONGS_AVAILABLE);
|
||||||
|
|
||||||
template <class T, size_t Tnum_files, Subdirectory Tsubdir>
|
template <class T, size_t Tnum_files, bool Tsearch_in_tars>
|
||||||
/* static */ const char * const *BaseSet<T, Tnum_files, Tsubdir>::file_names = _music_file_names;
|
/* static */ const char * const *BaseSet<T, Tnum_files, Tsearch_in_tars>::file_names = _music_file_names;
|
||||||
|
|
||||||
template <class Tbase_set>
|
template <class Tbase_set>
|
||||||
/* static */ const char *BaseMedia<Tbase_set>::GetExtension()
|
/* static */ const char *BaseMedia<Tbase_set>::GetExtension()
|
||||||
@ -60,7 +60,7 @@ template <class Tbase_set>
|
|||||||
|
|
||||||
bool MusicSet::FillSetDetails(IniFile *ini, const char *path, const char *full_filename)
|
bool MusicSet::FillSetDetails(IniFile *ini, const char *path, const char *full_filename)
|
||||||
{
|
{
|
||||||
bool ret = this->BaseSet<MusicSet, NUM_SONGS_AVAILABLE, GM_DIR>::FillSetDetails(ini, path, full_filename);
|
bool ret = this->BaseSet<MusicSet, NUM_SONGS_AVAILABLE, false>::FillSetDetails(ini, path, full_filename);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
this->num_available = 0;
|
this->num_available = 0;
|
||||||
IniGroup *names = ini->GetGroup("names");
|
IniGroup *names = ini->GetGroup("names");
|
||||||
|
@ -281,8 +281,8 @@ INSTANTIATE_BASE_MEDIA_METHODS(BaseMedia<SoundsSet>, SoundsSet)
|
|||||||
static const char * const _sound_file_names[] = { "samples" };
|
static const char * const _sound_file_names[] = { "samples" };
|
||||||
|
|
||||||
|
|
||||||
template <class T, size_t Tnum_files, Subdirectory Tsubdir>
|
template <class T, size_t Tnum_files, bool Tsearch_in_tars>
|
||||||
/* static */ const char * const *BaseSet<T, Tnum_files, Tsubdir>::file_names = _sound_file_names;
|
/* static */ const char * const *BaseSet<T, Tnum_files, Tsearch_in_tars>::file_names = _sound_file_names;
|
||||||
|
|
||||||
template <class Tbase_set>
|
template <class Tbase_set>
|
||||||
/* static */ const char *BaseMedia<Tbase_set>::GetExtension()
|
/* static */ const char *BaseMedia<Tbase_set>::GetExtension()
|
||||||
|
Loading…
Reference in New Issue
Block a user