mirror of https://github.com/OpenTTD/OpenTTD
(svn r27755) -Codechange: Move TAB_SIZE to strings_type.h and use it consistently.
parent
9ad09627ad
commit
f4da8ece0c
|
@ -16,13 +16,12 @@
|
||||||
#ifdef WITH_ICU_SORT
|
#ifdef WITH_ICU_SORT
|
||||||
#include <unicode/coll.h>
|
#include <unicode/coll.h>
|
||||||
#endif /* WITH_ICU_SORT */
|
#endif /* WITH_ICU_SORT */
|
||||||
|
#include "strings_type.h"
|
||||||
|
|
||||||
static const uint8 CASE_GENDER_LEN = 16; ///< The (maximum) length of a case/gender string.
|
static const uint8 CASE_GENDER_LEN = 16; ///< The (maximum) length of a case/gender string.
|
||||||
static const uint8 MAX_NUM_GENDERS = 8; ///< Maximum number of supported genders.
|
static const uint8 MAX_NUM_GENDERS = 8; ///< Maximum number of supported genders.
|
||||||
static const uint8 MAX_NUM_CASES = 16; ///< Maximum number of supported cases.
|
static const uint8 MAX_NUM_CASES = 16; ///< Maximum number of supported cases.
|
||||||
|
|
||||||
static const uint TAB_SIZE_BITS = 11; ///< The number of bits used for the tab size.
|
|
||||||
static const uint TAB_SIZE = 1 << TAB_SIZE_BITS; ///< The number of values in a tab.
|
|
||||||
static const uint TAB_COUNT_BITS = 5; ///< The number of bits used for the amount of tabs.
|
static const uint TAB_COUNT_BITS = 5; ///< The number of bits used for the amount of tabs.
|
||||||
static const uint TAB_COUNT = 1 << TAB_COUNT_BITS; ///< The amount of tabs.
|
static const uint TAB_COUNT = 1 << TAB_COUNT_BITS; ///< The amount of tabs.
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,6 @@
|
||||||
#include "safeguards.h"
|
#include "safeguards.h"
|
||||||
|
|
||||||
#define GRFTAB 28
|
#define GRFTAB 28
|
||||||
#define TABSIZE 11
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Explains the newgrf shift bit positioning.
|
* Explains the newgrf shift bit positioning.
|
||||||
|
@ -159,7 +158,7 @@ struct GRFTextEntry {
|
||||||
|
|
||||||
|
|
||||||
static uint _num_grf_texts = 0;
|
static uint _num_grf_texts = 0;
|
||||||
static GRFTextEntry _grf_text[(1 << TABSIZE) * 3];
|
static GRFTextEntry _grf_text[TAB_SIZE * 3];
|
||||||
static byte _currentLangID = GRFLX_ENGLISH; ///< by default, english is used.
|
static byte _currentLangID = GRFLX_ENGLISH; ///< by default, english is used.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -696,7 +695,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);
|
grfmsg(3, "Added 0x%X: grfid %08X string 0x%X lang 0x%X string '%s'", id, grfid, stringid, newtext->langid, newtext->text);
|
||||||
|
|
||||||
return (GRFTAB << TABSIZE) + id;
|
return MakeStringID(GRFTAB, 0) + id; // Id reaches across multiple tabs
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -706,7 +705,7 @@ StringID GetGRFStringID(uint32 grfid, uint16 stringid)
|
||||||
{
|
{
|
||||||
for (uint id = 0; id < _num_grf_texts; id++) {
|
for (uint id = 0; id < _num_grf_texts; id++) {
|
||||||
if (_grf_text[id].grfid == grfid && _grf_text[id].stringid == stringid) {
|
if (_grf_text[id].grfid == grfid && _grf_text[id].stringid == stringid) {
|
||||||
return (GRFTAB << TABSIZE) + id;
|
return MakeStringID(GRFTAB, 0) + id; // Id reaches across multiple tabs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
*/
|
*/
|
||||||
static inline uint GetStringTab(StringID str)
|
static inline uint GetStringTab(StringID str)
|
||||||
{
|
{
|
||||||
return GB(str, 11, 5);
|
return GB(str, TAB_SIZE_BITS, 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,7 +34,7 @@ static inline uint GetStringTab(StringID str)
|
||||||
*/
|
*/
|
||||||
static inline uint GetStringIndex(StringID str)
|
static inline uint GetStringIndex(StringID str)
|
||||||
{
|
{
|
||||||
return GB(str, 0, 11);
|
return GB(str, 0, TAB_SIZE_BITS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,7 +45,8 @@ static inline uint GetStringIndex(StringID str)
|
||||||
*/
|
*/
|
||||||
static inline StringID MakeStringID(uint tab, uint index)
|
static inline StringID MakeStringID(uint tab, uint index)
|
||||||
{
|
{
|
||||||
return tab << 11 | index;
|
assert(index < TAB_SIZE);
|
||||||
|
return tab << TAB_SIZE_BITS | index;
|
||||||
}
|
}
|
||||||
|
|
||||||
class StringParameters {
|
class StringParameters {
|
||||||
|
|
|
@ -26,6 +26,11 @@ enum TextDirection {
|
||||||
TD_RTL, ///< Text is written right-to-left by default
|
TD_RTL, ///< Text is written right-to-left by default
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Number of bits for the StringIndex within a StringTab */
|
||||||
|
static const uint TAB_SIZE_BITS = 11;
|
||||||
|
/** Number of strings per StringTab */
|
||||||
|
static const uint TAB_SIZE = 1 << TAB_SIZE_BITS;
|
||||||
|
|
||||||
/** Special string constants */
|
/** Special string constants */
|
||||||
enum SpecialStrings {
|
enum SpecialStrings {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue