summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2017-02-26 19:41:30 +0000
committerfrosch <frosch@openttd.org>2017-02-26 19:41:30 +0000
commit2bb80d280cc39684e71be6c4c2db5bf500e10b1c (patch)
tree2e5a9bb6dbd454860fa195da5dc537009a57d572 /src
parentfc4c4d080c5d95d92354cefac4a05082fc417c83 (diff)
downloadopenttd-2bb80d280cc39684e71be6c4c2db5bf500e10b1c.tar.xz
(svn r27758) -Change: Increase the maximum number of GameScript texts to 64k, and NewGRF texts to 512k.
Diffstat (limited to 'src')
-rw-r--r--src/newgrf_text.cpp6
-rw-r--r--src/script/api/script_error.cpp5
-rw-r--r--src/strings.cpp31
-rw-r--r--src/strings_func.h19
-rw-r--r--src/strings_type.h14
5 files changed, 39 insertions, 36 deletions
diff --git a/src/newgrf_text.cpp b/src/newgrf_text.cpp
index 279bd094c..e4b3c382b 100644
--- a/src/newgrf_text.cpp
+++ b/src/newgrf_text.cpp
@@ -156,7 +156,7 @@ struct GRFTextEntry {
static uint _num_grf_texts = 0;
-static GRFTextEntry _grf_text[TAB_SIZE * 3];
+static GRFTextEntry _grf_text[TAB_SIZE_NEWGRF];
static byte _currentLangID = GRFLX_ENGLISH; ///< by default, english is used.
/**
@@ -693,7 +693,7 @@ StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool ne
grfmsg(3, "Added 0x%X: grfid %08X string 0x%X lang 0x%X string '%s'", id, grfid, stringid, newtext->langid, newtext->text);
- return MakeStringID(TEXT_TAB_NEWGRF1, 0) + id; // Id reaches across multiple tabs
+ return MakeStringID(TEXT_TAB_NEWGRF_START, id);
}
/**
@@ -703,7 +703,7 @@ StringID GetGRFStringID(uint32 grfid, uint16 stringid)
{
for (uint id = 0; id < _num_grf_texts; id++) {
if (_grf_text[id].grfid == grfid && _grf_text[id].stringid == stringid) {
- return MakeStringID(TEXT_TAB_NEWGRF1, 0) + id; // Id reaches across multiple tabs
+ return MakeStringID(TEXT_TAB_NEWGRF_START, id);
}
}
diff --git a/src/script/api/script_error.cpp b/src/script/api/script_error.cpp
index b692c74f4..24c491995 100644
--- a/src/script/api/script_error.cpp
+++ b/src/script/api/script_error.cpp
@@ -34,9 +34,8 @@ ScriptError::ScriptErrorMapString ScriptError::error_map_string = ScriptError::S
{
uint index = GetStringIndex(internal_string_id);
switch (GetStringTab(internal_string_id)) {
- case TEXT_TAB_NEWGRF1:
- case TEXT_TAB_NEWGRF2:
- case TEXT_TAB_NEWGRF3:
+ case TEXT_TAB_NEWGRF_START:
+ case TEXT_TAB_GAMESCRIPT_START:
return ERR_NEWGRF_SUPPLIED_ERROR; // NewGRF strings.
case TEXT_TAB_SPECIAL:
diff --git a/src/strings.cpp b/src/strings.cpp
index 0d115def9..1c539d934 100644
--- a/src/strings.cpp
+++ b/src/strings.cpp
@@ -195,12 +195,10 @@ static bool _scan_for_gender_data = false; ///< Are we scanning for the gender
const char *GetStringPtr(StringID string)
{
switch (GetStringTab(string)) {
- case TEXT_TAB_GAMESCRIPT: return GetGameStringPtr(GetStringIndex(string));
+ case TEXT_TAB_GAMESCRIPT_START: return GetGameStringPtr(GetStringIndex(string));
/* 0xD0xx and 0xD4xx IDs have been converted earlier. */
case TEXT_TAB_OLD_NEWGRF: NOT_REACHED();
- case TEXT_TAB_NEWGRF1: return GetGRFStringPtr(GetStringIndex(string));
- case TEXT_TAB_NEWGRF2: return GetGRFStringPtr(GetStringIndex(string) + 0x0800);
- case TEXT_TAB_NEWGRF3: return GetGRFStringPtr(GetStringIndex(string) + 0x1000);
+ case TEXT_TAB_NEWGRF_START: return GetGRFStringPtr(GetStringIndex(string));
default: return _langpack_offs[_langtab_start[GetStringTab(string)] + GetStringIndex(string)];
}
}
@@ -242,21 +240,15 @@ char *GetStringWithArgs(char *buffr, StringID string, StringParameters *args, co
}
break;
- case TEXT_TAB_GAMESCRIPT:
+ case TEXT_TAB_GAMESCRIPT_START:
return FormatString(buffr, GetGameStringPtr(index), args, last, case_index, true);
case TEXT_TAB_OLD_NEWGRF:
NOT_REACHED();
- case TEXT_TAB_NEWGRF1:
+ case TEXT_TAB_NEWGRF_START:
return FormatString(buffr, GetGRFStringPtr(index), args, last, case_index);
- case TEXT_TAB_NEWGRF2:
- return FormatString(buffr, GetGRFStringPtr(index + 0x0800), args, last, case_index);
-
- case TEXT_TAB_NEWGRF3:
- return FormatString(buffr, GetGRFStringPtr(index + 0x1000), args, last, case_index);
-
default:
break;
}
@@ -825,17 +817,16 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
sub_args.ClearTypeInformation();
memset(sub_args_need_free, 0, sizeof(sub_args_need_free));
- uint16 stringid;
const char *s = str;
char *p;
- stringid = strtol(str, &p, 16);
+ uint32 stringid = strtoul(str, &p, 16);
if (*p != ':' && *p != '\0') {
while (*p != '\0') p++;
str = p;
buff = strecat(buff, "(invalid SCC_ENCODED)", last);
break;
}
- if (stringid >= TAB_SIZE) {
+ if (stringid >= TAB_SIZE_GAMESCRIPT) {
while (*p != '\0') p++;
str = p;
buff = strecat(buff, "(invalid StringID)", last);
@@ -883,13 +874,13 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
param = strtoull(s, &p, 16);
if (lookup) {
- if (param >= TAB_SIZE) {
+ if (param >= TAB_SIZE_GAMESCRIPT) {
while (*p != '\0') p++;
str = p;
buff = strecat(buff, "(invalid sub-StringID)", last);
break;
}
- param = MakeStringID(TEXT_TAB_GAMESCRIPT, param);
+ param = MakeStringID(TEXT_TAB_GAMESCRIPT_START, param);
}
sub_args.SetParam(i++, param);
@@ -904,7 +895,7 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
/* If we didn't error out, we can actually print the string. */
if (*str != '\0') {
str = p;
- buff = GetStringWithArgs(buff, MakeStringID(TEXT_TAB_GAMESCRIPT, stringid), &sub_args, last, true);
+ buff = GetStringWithArgs(buff, MakeStringID(TEXT_TAB_GAMESCRIPT_START, stringid), &sub_args, last, true);
}
for (int i = 0; i < 20; i++) {
@@ -1020,7 +1011,7 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
case SCC_STRING: {// {STRING}
StringID str = args->GetInt32(SCC_STRING);
- if (game_script && GetStringTab(str) != TEXT_TAB_GAMESCRIPT) break;
+ if (game_script && GetStringTab(str) != TEXT_TAB_GAMESCRIPT_START) break;
/* WARNING. It's prohibited for the included string to consume any arguments.
* For included strings that consume argument, you should use STRING1, STRING2 etc.
* To debug stuff you can set argv to NULL and it will tell you */
@@ -1039,7 +1030,7 @@ static char *FormatString(char *buff, const char *str_arg, StringParameters *arg
case SCC_STRING7: { // {STRING1..7}
/* Strings that consume arguments */
StringID str = args->GetInt32(b);
- if (game_script && GetStringTab(str) != TEXT_TAB_GAMESCRIPT) break;
+ if (game_script && GetStringTab(str) != TEXT_TAB_GAMESCRIPT_START) break;
uint size = b - SCC_STRING1 + 1;
if (game_script && size > args->GetDataLeft()) {
buff = strecat(buff, "(too many parameters)", last);
diff --git a/src/strings_func.h b/src/strings_func.h
index 7ad20eb1f..0da711bc4 100644
--- a/src/strings_func.h
+++ b/src/strings_func.h
@@ -24,7 +24,10 @@
*/
static inline StringTab GetStringTab(StringID str)
{
- return (StringTab)GB(str, TAB_SIZE_BITS, 5);
+ StringTab result = (StringTab)(str >> TAB_SIZE_BITS);
+ if (result >= TEXT_TAB_NEWGRF_START) return TEXT_TAB_NEWGRF_START;
+ if (result >= TEXT_TAB_GAMESCRIPT_START) return TEXT_TAB_GAMESCRIPT_START;
+ return result;
}
/**
@@ -34,7 +37,7 @@ static inline StringTab GetStringTab(StringID str)
*/
static inline uint GetStringIndex(StringID str)
{
- return GB(str, 0, TAB_SIZE_BITS);
+ return str - (GetStringTab(str) << TAB_SIZE_BITS);
}
/**
@@ -45,9 +48,15 @@ static inline uint GetStringIndex(StringID str)
*/
static inline StringID MakeStringID(StringTab tab, uint index)
{
- assert(tab < TEXT_TAB_END);
- assert(index < TAB_SIZE);
- return tab << TAB_SIZE_BITS | index;
+ if (tab == TEXT_TAB_NEWGRF_START) {
+ assert(index < TAB_SIZE_NEWGRF);
+ } else if (tab == TEXT_TAB_GAMESCRIPT_START) {
+ assert(index < TAB_SIZE_GAMESCRIPT);
+ } else {
+ assert(tab < TEXT_TAB_END);
+ assert(index < TAB_SIZE);
+ }
+ return (tab << TAB_SIZE_BITS) + index;
}
class StringParameters {
diff --git a/src/strings_type.h b/src/strings_type.h
index f8144f79f..aa3ed788c 100644
--- a/src/strings_type.h
+++ b/src/strings_type.h
@@ -36,12 +36,10 @@ enum StringTab {
TEXT_TAB_OLD_CUSTOM = 15,
TEXT_TAB_VEHICLE = 16,
/* Tab 17 for regular strings */
- TEXT_TAB_GAMESCRIPT = 18,
TEXT_TAB_OLD_NEWGRF = 26,
- TEXT_TAB_NEWGRF1 = 28,
- TEXT_TAB_NEWGRF2 = 29,
- TEXT_TAB_NEWGRF3 = 30,
- TEXT_TAB_END = 32
+ TEXT_TAB_END = 32, ///< End of language files.
+ TEXT_TAB_GAMESCRIPT_START = 32, ///< Start of GameScript supplied strings.
+ TEXT_TAB_NEWGRF_START = 64, ///< Start of NewGRF supplied strings.
};
/** Number of bits for the StringIndex within a StringTab */
@@ -49,6 +47,12 @@ static const uint TAB_SIZE_BITS = 11;
/** Number of strings per StringTab */
static const uint TAB_SIZE = 1 << TAB_SIZE_BITS;
+/** Number of strings for GameScripts */
+static const uint TAB_SIZE_GAMESCRIPT = TAB_SIZE * 32;
+
+/** Number of strings for NewGRFs */
+static const uint TAB_SIZE_NEWGRF = TAB_SIZE * 256;
+
/** Special string constants */
enum SpecialStrings {