Add non-animated SSSE3 blitter
[openttd/fttd.git] / src / music.cpp
blob55599a947b9c4b4256677fc9ff8bfcb3f96610a0
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * OpenTTD 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, version 2.
6 * OpenTTD 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.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8 */
10 /** @file music.cpp The songs that OpenTTD knows. */
12 #include "stdafx.h"
14 /** The type of set we're replacing */
15 #define SET_TYPE "music"
16 #include "base_media_func.h"
18 INSTANTIATE_BASE_MEDIA_METHODS(BaseMedia<MusicSet>, MusicSet)
20 /** Names corresponding to the music set's files */
21 static const char * const _music_file_names[] = {
22 "theme",
23 "old_0", "old_1", "old_2", "old_3", "old_4", "old_5", "old_6", "old_7", "old_8", "old_9",
24 "new_0", "new_1", "new_2", "new_3", "new_4", "new_5", "new_6", "new_7", "new_8", "new_9",
25 "ezy_0", "ezy_1", "ezy_2", "ezy_3", "ezy_4", "ezy_5", "ezy_6", "ezy_7", "ezy_8", "ezy_9",
27 /** Make sure we aren't messing things up. */
28 assert_compile(lengthof(_music_file_names) == NUM_SONGS_AVAILABLE);
30 template <class T, size_t Tnum_files, bool Tsearch_in_tars>
31 /* static */ const char * const *BaseSet<T, Tnum_files, Tsearch_in_tars>::file_names = _music_file_names;
33 template <class Tbase_set>
34 /* static */ const char *BaseMedia<Tbase_set>::GetExtension()
36 return ".obm"; // OpenTTD Base Music
39 template <class Tbase_set>
40 /* static */ bool BaseMedia<Tbase_set>::DetermineBestSet()
42 if (BaseMedia<Tbase_set>::used_set != NULL) return true;
44 const Tbase_set *best = NULL;
45 for (const Tbase_set *c = BaseMedia<Tbase_set>::available_sets; c != NULL; c = c->next) {
46 if (c->GetNumMissing() != 0) continue;
48 if (best == NULL ||
49 (best->fallback && !c->fallback) ||
50 best->valid_files < c->valid_files ||
51 (best->valid_files == c->valid_files &&
52 (best->shortname == c->shortname && best->version < c->version))) {
53 best = c;
57 BaseMedia<Tbase_set>::used_set = best;
58 return BaseMedia<Tbase_set>::used_set != NULL;
61 bool MusicSet::FillSetDetails(IniFile *ini, const char *path, const char *full_filename)
63 bool ret = this->BaseSet<MusicSet, NUM_SONGS_AVAILABLE, false>::FillSetDetails(ini, path, full_filename);
64 if (ret) {
65 this->num_available = 0;
66 IniGroup *names = ini->GetGroup("names");
67 for (uint i = 0, j = 1; i < lengthof(this->song_name); i++) {
68 const char *filename = this->files[i].filename;
69 if (names == NULL || StrEmpty(filename)) {
70 this->song_name[i][0] = '\0';
71 continue;
74 IniItem *item = NULL;
75 /* As we possibly add a path to the filename and we compare
76 * on the filename with the path as in the .obm, we need to
77 * keep stripping path elements until we find a match. */
78 for (const char *p = filename; p != NULL; p = strchr(p, PATHSEPCHAR)) {
79 /* Remove possible double path separator characters from
80 * the beginning, so we don't start reading e.g. root. */
81 while (*p == PATHSEPCHAR) p++;
83 item = names->GetItem(p, false);
84 if (item != NULL && !StrEmpty(item->value)) break;
87 if (item == NULL || StrEmpty(item->value)) {
88 DEBUG(grf, 0, "Base music set song name missing: %s", filename);
89 return false;
92 strecpy(this->song_name[i], item->value, lastof(this->song_name[i]));
93 this->track_nr[i] = j++;
94 this->num_available++;
97 return ret;