Bump max map size to 28 bits.

Prevent opening NewGRF debug window on tile indexes > 27 bits,
to avoid overflowing field.
pull/3/head
Jonathan G Rennison 9 years ago
parent 5934cc4995
commit 1891e7dfc8

@ -723,11 +723,11 @@ void RunTileLoop()
* shift register (LFSR). This allows a deterministic pseudorandom ordering, but
* still with minimal state and fast iteration. */
/* Maximal length LFSR feedback terms, from 12-bit (for 64x64 maps) to 26-bit (for 8kx8k maps).
/* Maximal length LFSR feedback terms, from 12-bit (for 64x64 maps) to 28-bit (for 16kx16k maps).
* Extracted from http://www.ece.cmu.edu/~koopman/lfsr/ */
static const uint32 feedbacks[] = {
0xD8F, 0x1296, 0x2496, 0x4357, 0x8679, 0x1030E, 0x206CD, 0x403FE, 0x807B8, 0x1004B2, 0x2006A8,
0x4004B2, 0x800B87, 0x10004F3, 0x200072D,
0x4004B2, 0x800B87, 0x10004F3, 0x200072D, 0x40006AE, 0x80009E3,
};
assert_compile(lengthof(feedbacks) == MAX_MAP_TILES_BITS - 2 * MIN_MAP_SIZE_BITS + 1);
const uint32 feedback = feedbacks[MapLogX() + MapLogY() - 2 * MIN_MAP_SIZE_BITS];

@ -63,10 +63,10 @@ struct TileIndexDiffC {
/** Minimal and maximal map width and height */
static const uint MIN_MAP_SIZE_BITS = 6; ///< Minimal size of map is equal to 2 ^ MIN_MAP_SIZE_BITS
static const uint MAX_MAP_SIZE_BITS = 20; ///< Maximal size of map is equal to 2 ^ MAX_MAP_SIZE_BITS
static const uint MAX_MAP_TILES_BITS = 26; ///< Maximal number of tiles in a map is equal to 2 ^ MAX_MAP_TILES_BITS.
static const uint MAX_MAP_TILES_BITS = 28; ///< Maximal number of tiles in a map is equal to 2 ^ MAX_MAP_TILES_BITS.
static const uint MIN_MAP_SIZE = 1 << MIN_MAP_SIZE_BITS; ///< Minimal map size = 64
static const uint MAX_MAP_SIZE = 1 << MAX_MAP_SIZE_BITS; ///< Maximal map size = 1M
static const uint MAX_MAP_TILES = 1 << MAX_MAP_TILES_BITS;///< Maximal number of tiles in a map = 64M
static const uint MAX_MAP_TILES = 1 << MAX_MAP_TILES_BITS;///< Maximal number of tiles in a map = 256M (16k x 16k)
/**
* Approximation of the length of a straight track, relative to a diagonal

@ -699,6 +699,7 @@ static WindowDesc _newgrf_inspect_desc(
*/
void ShowNewGRFInspectWindow(GrfSpecFeature feature, uint index, const uint32 grfid)
{
if (index >= (1 << 27)) return;
if (!IsNewGRFInspectable(feature, index)) return;
WindowNumber wno = GetInspectWindowNumber(feature, index);
@ -718,6 +719,7 @@ void ShowNewGRFInspectWindow(GrfSpecFeature feature, uint index, const uint32 gr
void InvalidateNewGRFInspectWindow(GrfSpecFeature feature, uint index)
{
if (feature == GSF_INVALID) return;
if (index >= (1 << 27)) return;
WindowNumber wno = GetInspectWindowNumber(feature, index);
InvalidateWindowData(WC_NEWGRF_INSPECT, wno);
@ -734,6 +736,7 @@ void InvalidateNewGRFInspectWindow(GrfSpecFeature feature, uint index)
void DeleteNewGRFInspectWindow(GrfSpecFeature feature, uint index)
{
if (feature == GSF_INVALID) return;
if (index >= (1 << 27)) return;
WindowNumber wno = GetInspectWindowNumber(feature, index);
DeleteWindowById(WC_NEWGRF_INSPECT, wno);
@ -755,6 +758,7 @@ void DeleteNewGRFInspectWindow(GrfSpecFeature feature, uint index)
*/
bool IsNewGRFInspectable(GrfSpecFeature feature, uint index)
{
if (index >= (1 << 27)) return false;
const NIFeature *nif = GetFeature(GetInspectWindowNumber(feature, index));
if (nif == NULL) return false;
return nif->helper->IsInspectable(index);

Loading…
Cancel
Save