base_media_base.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #ifndef BASE_MEDIA_BASE_H
00013 #define BASE_MEDIA_BASE_H
00014
00015 #include "fileio_func.h"
00016 #include "core/smallmap_type.hpp"
00017 #include "gfx_type.h"
00018
00019
00020 struct IniFile;
00021 struct ContentInfo;
00022
00024 struct MD5File {
00026 enum ChecksumResult {
00027 CR_MATCH,
00028 CR_MISMATCH,
00029 CR_NO_FILE,
00030 };
00031
00032 const char *filename;
00033 uint8 hash[16];
00034 const char *missing_warning;
00035
00036 ChecksumResult CheckMD5(Subdirectory subdir) const;
00037 };
00038
00045 template <class T, size_t Tnum_files, Subdirectory Tsubdir>
00046 struct BaseSet {
00047 typedef SmallMap<const char *, const char *> TranslatedStrings;
00048
00050 static const size_t NUM_FILES = Tnum_files;
00051
00053 static const Subdirectory SUBDIR = Tsubdir;
00054
00056 static const char * const *file_names;
00057
00058 const char *name;
00059 TranslatedStrings description;
00060 uint32 shortname;
00061 uint32 version;
00062
00063 MD5File files[NUM_FILES];
00064 uint found_files;
00065 uint valid_files;
00066
00067 T *next;
00068
00070 ~BaseSet()
00071 {
00072 free((void*)this->name);
00073
00074 for (TranslatedStrings::iterator iter = this->description.Begin(); iter != this->description.End(); iter++) {
00075 free((void*)iter->first);
00076 free((void*)iter->second);
00077 }
00078
00079 for (uint i = 0; i < NUM_FILES; i++) {
00080 free((void*)this->files[i].filename);
00081 free((void*)this->files[i].missing_warning);
00082 }
00083
00084 delete this->next;
00085 }
00086
00091 int GetNumMissing() const
00092 {
00093 return Tnum_files - this->found_files;
00094 }
00095
00101 int GetNumInvalid() const
00102 {
00103 return Tnum_files - this->valid_files;
00104 }
00105
00112 bool FillSetDetails(IniFile *ini, const char *path);
00113
00122 const char *GetDescription(const char *isocode = NULL) const
00123 {
00124 if (isocode != NULL) {
00125
00126 for (TranslatedStrings::const_iterator iter = this->description.Begin(); iter != this->description.End(); iter++) {
00127 if (strcmp(iter->first, isocode) == 0) return iter->second;
00128 }
00129
00130 for (TranslatedStrings::const_iterator iter = this->description.Begin(); iter != this->description.End(); iter++) {
00131 if (strncmp(iter->first, isocode, 2) == 0) return iter->second;
00132 }
00133 }
00134
00135 return this->description.Begin()->second;
00136 }
00137 };
00138
00143 template <class Tbase_set>
00144 class BaseMedia : FileScanner {
00145 protected:
00146 static Tbase_set *available_sets;
00147 static const Tbase_set *used_set;
00148
00149 bool AddFile(const char *filename, size_t basepath_length);
00150
00155 static const char *GetExtension();
00156 public:
00158 static const char *ini_set;
00159
00165 static bool DetermineBestSet();
00166
00168 static uint FindSets()
00169 {
00170 BaseMedia<Tbase_set> fs;
00171 return fs.Scan(GetExtension(), Tbase_set::SUBDIR);
00172 }
00173
00179 static bool SetSet(const char *name);
00180
00187 static char *GetSetsList(char *p, const char *last);
00188
00193 static int GetNumSets();
00194
00199 static int GetIndexOfUsedSet();
00200
00205 static const Tbase_set *GetSet(int index);
00210 static const Tbase_set *GetUsedSet();
00211
00218 static bool HasSet(const ContentInfo *ci, bool md5sum);
00219 };
00220
00221
00223 enum GraphicsFileType {
00224 GFT_BASE,
00225 GFT_LOGOS,
00226 GFT_ARCTIC,
00227 GFT_TROPICAL,
00228 GFT_TOYLAND,
00229 GFT_EXTRA,
00230 MAX_GFT
00231 };
00232
00234 struct GraphicsSet : BaseSet<GraphicsSet, MAX_GFT, DATA_DIR> {
00235 PaletteType palette;
00236
00237 bool FillSetDetails(struct IniFile *ini, const char *path);
00238 };
00239
00241 class BaseGraphics : public BaseMedia<GraphicsSet> {
00242 public:
00246 static void DeterminePalette();
00247 };
00248
00250 struct SoundsSet : BaseSet<SoundsSet, 1, DATA_DIR> {
00251 };
00252
00254 class BaseSounds : public BaseMedia<SoundsSet> {
00255 public:
00256 };
00257
00259 static const uint NUM_SONGS_CLASS = 10;
00261 static const uint NUM_SONG_CLASSES = 3;
00263 static const uint NUM_SONGS_AVAILABLE = 1 + NUM_SONG_CLASSES * NUM_SONGS_CLASS;
00264
00266 static const uint NUM_SONGS_PLAYLIST = 32;
00267
00269 struct MusicSet : BaseSet<MusicSet, NUM_SONGS_AVAILABLE, GM_DIR> {
00271 char song_name[NUM_SONGS_AVAILABLE][32];
00272 byte track_nr[NUM_SONGS_AVAILABLE];
00273 byte num_available;
00274
00275 bool FillSetDetails(struct IniFile *ini, const char *path);
00276 };
00277
00279 class BaseMusic : public BaseMedia<MusicSet> {
00280 public:
00281 };
00282
00283 #endif