Mercurial > hg > openttd
changeset 18723:8469a2691595 draft
(svn r23571) -Codechange: make the number of 'tabs' the generate configurable
author | rubidium <rubidium@openttd.org> |
---|---|
date | Sat, 17 Dec 2011 15:02:09 +0000 |
parents | 5960bf05d0c7 |
children | fc2ada8c1779 |
files | src/strgen/strgen.cpp |
diffstat | 1 files changed, 25 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/src/strgen/strgen.cpp +++ b/src/strgen/strgen.cpp @@ -109,8 +109,11 @@ /** Information about the currently known strings. */ struct StringData { + static const uint STRINGS_IN_TAB = 2048; + LangString **strings; ///< Array of all known strings. uint16 *hash_heads; ///< Hash table for the strings. + size_t tabs; ///< The number of 'tabs' of strings. size_t max_strings; ///< The maxmimum number of strings. int next_string_id; ///< The next string ID to allocate. @@ -118,7 +121,7 @@ * Create a new string data container. * @param max_strings The maximum number of strings. */ - StringData(size_t max_strings = 65536) : max_strings(max_strings) + StringData(size_t tabs = 32) : tabs(tabs), max_strings(tabs * STRINGS_IN_TAB) { this->strings = CallocT<LangString *>(max_strings); this->hash_heads = CallocT<uint16>(max_strings); @@ -227,6 +230,17 @@ return hash; } + + /** + * Count the number of tab elements that are in use. + * @param tab The tab to count the elements of. + */ + uint CountInUse(uint tab) const + { + int i; + for (i = STRINGS_IN_TAB; --i >= 0;) if (this->strings[(tab * STRINGS_IN_TAB) + i] != NULL) break; + return i + 1; + } }; static LanguagePackHeader _lang; ///< Header information about a language. @@ -942,16 +956,6 @@ } } - -static uint CountInUse(const StringData &data, uint grp) -{ - int i; - - for (i = 0x800; --i >= 0;) if (data.strings[(grp << 11) + i] != NULL) break; - return i + 1; -} - - bool CompareFiles(const char *n1, const char *n2) { FILE *f2 = fopen(n2, "rb"); @@ -1233,15 +1237,15 @@ */ void WriteLang(const StringData &data) { - uint in_use[32]; - for (int i = 0; i != 32; i++) { - uint n = CountInUse(data, i); + uint in_use[data.tabs]; + for (size_t tab = 0; tab < data.tabs; tab++) { + uint n = data.CountInUse(tab); - in_use[i] = n; - _lang.offsets[i] = TO_LE16(n); + in_use[tab] = n; + _lang.offsets[tab] = TO_LE16(n); - for (uint j = 0; j != in_use[i]; j++) { - const LangString *ls = data.strings[(i << 11) + j]; + for (uint j = 0; j != in_use[tab]; j++) { + const LangString *ls = data.strings[(tab * StringData::STRINGS_IN_TAB) + j]; if (ls != NULL && ls->translated == NULL) _lang.missing++; } } @@ -1254,9 +1258,9 @@ this->WriteHeader(&_lang); Buffer buffer; - for (int i = 0; i != 32; i++) { - for (uint j = 0; j != in_use[i]; j++) { - const LangString *ls = data.strings[(i << 11) + j]; + for (size_t tab = 0; tab < data.tabs; tab++) { + for (uint j = 0; j != in_use[tab]; j++) { + const LangString *ls = data.strings[(tab * StringData::STRINGS_IN_TAB) + j]; const Case *casep; const char *cmdp;