Merge branch 'extra_large_maps-sx' into jgrpp

Conflicts:
	src/saveload/extended_ver_sl.cpp
	src/saveload/extended_ver_sl.h
This commit is contained in:
Jonathan G Rennison
2015-09-12 14:19:26 +01:00
5 changed files with 35 additions and 11 deletions

View File

@@ -32,6 +32,25 @@ uint _map_tile_mask; ///< _map_size - 1 (to mask the mapsize)
Tile *_m = NULL; ///< Tiles of the map Tile *_m = NULL; ///< Tiles of the map
TileExtended *_me = NULL; ///< Extended Tiles of the map TileExtended *_me = NULL; ///< Extended Tiles of the map
/**
* Validates whether a map with the given dimension is valid
* @param size_x the width of the map along the NE/SW edge
* @param size_y the 'height' of the map along the SE/NW edge
* @return true if valid, or false if not valid
*/
bool ValidateMapSize(uint size_x, uint size_y)
{
/* Make sure that the map size is within the limits and that
* size of both axes is a power of 2. */
if (size_x * size_y > MAX_MAP_TILES ||
size_x < MIN_MAP_SIZE ||
size_y < MIN_MAP_SIZE ||
(size_x & (size_x - 1)) != 0 ||
(size_y & (size_y - 1)) != 0) {
return false;
}
return true;
}
/** /**
* (Re)allocates a map with the given dimension * (Re)allocates a map with the given dimension
@@ -43,13 +62,7 @@ void AllocateMap(uint size_x, uint size_y)
DEBUG(map, 2, "Min/max map size %d/%d, max map tiles %d", MIN_MAP_SIZE, MAX_MAP_SIZE, MAX_MAP_TILES); DEBUG(map, 2, "Min/max map size %d/%d, max map tiles %d", MIN_MAP_SIZE, MAX_MAP_SIZE, MAX_MAP_TILES);
DEBUG(map, 1, "Allocating map of size %dx%d", size_x, size_y); DEBUG(map, 1, "Allocating map of size %dx%d", size_x, size_y);
/* Make sure that the map size is within the limits and that if (!ValidateMapSize(size_x, size_y)) {
* size of both axes is a power of 2. */
if (size_x * size_y > MAX_MAP_TILES ||
size_x < MIN_MAP_SIZE ||
size_y < MIN_MAP_SIZE ||
(size_x & (size_x - 1)) != 0 ||
(size_y & (size_y - 1)) != 0) {
error("Invalid map size"); error("Invalid map size");
} }

View File

@@ -43,6 +43,7 @@ extern Tile *_m;
*/ */
extern TileExtended *_me; extern TileExtended *_me;
bool ValidateMapSize(uint size_x, uint size_y);
void AllocateMap(uint size_x, uint size_y); void AllocateMap(uint size_x, uint size_y);
/** /**

View File

@@ -33,6 +33,7 @@
#include "saveload.h" #include "saveload.h"
#include "extended_ver_sl.h" #include "extended_ver_sl.h"
#include "../timetable.h" #include "../timetable.h"
#include "../map_func.h"
#include <vector> #include <vector>
@@ -62,6 +63,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
{ XSLFI_VARIABLE_DAY_LENGTH, XSCF_NULL, 1, 1, "variable_day_length", NULL, NULL, NULL }, { XSLFI_VARIABLE_DAY_LENGTH, XSCF_NULL, 1, 1, "variable_day_length", NULL, NULL, NULL },
{ XSLFI_ORDER_OCCUPANCY, XSCF_NULL, 1, 1, "order_occupancy", NULL, NULL, NULL }, { XSLFI_ORDER_OCCUPANCY, XSCF_NULL, 1, 1, "order_occupancy", NULL, NULL, NULL },
{ XSLFI_MORE_COND_ORDERS, XSCF_NULL, 1, 1, "more_cond_orders", NULL, NULL, NULL }, { XSLFI_MORE_COND_ORDERS, XSCF_NULL, 1, 1, "more_cond_orders", NULL, NULL, NULL },
{ XSLFI_EXTRA_LARGE_MAP, XSCF_NULL, 0, 1, "extra_large_map", NULL, NULL, NULL },
{ XSLFI_NULL, XSCF_NULL, 0, 0, NULL, NULL, NULL, NULL },// This is the end marker { XSLFI_NULL, XSCF_NULL, 0, 0, NULL, NULL, NULL, NULL },// This is the end marker
}; };
@@ -125,6 +127,9 @@ void SlXvSetCurrentState()
for (; info->index != XSLFI_NULL; ++info) { for (; info->index != XSLFI_NULL; ++info) {
_sl_xv_feature_versions[info->index] = info->save_version; _sl_xv_feature_versions[info->index] = info->save_version;
} }
if (MapSizeX() > 8192 || MapSizeY() > 8192) {
_sl_xv_feature_versions[XSLFI_EXTRA_LARGE_MAP] = 1;
}
} }
/** /**
@@ -220,7 +225,6 @@ static void Save_SLXI()
SlXvSetCurrentState(); SlXvSetCurrentState();
static const SaveLoad _xlsi_sub_chunk_desc[] = { static const SaveLoad _xlsi_sub_chunk_desc[] = {
SLE_VAR(SlxiSubChunkInfo, save_version, SLE_UINT16),
SLE_STR(SlxiSubChunkInfo, name, SLE_STR, 0), SLE_STR(SlxiSubChunkInfo, name, SLE_STR, 0),
SLE_END() SLE_END()
}; };
@@ -234,9 +238,9 @@ static void Save_SLXI()
chunk_counts.resize(XSLFI_SIZE); chunk_counts.resize(XSLFI_SIZE);
const SlxiSubChunkInfo *info = _sl_xv_sub_chunk_infos; const SlxiSubChunkInfo *info = _sl_xv_sub_chunk_infos;
for (; info->index != XSLFI_NULL; ++info) { for (; info->index != XSLFI_NULL; ++info) {
if (info->save_version > 0) { if (_sl_xv_feature_versions[info->index] > 0) {
item_count++; item_count++;
length += 4; length += 6;
length += SlCalcObjLength(info, _xlsi_sub_chunk_desc); length += SlCalcObjLength(info, _xlsi_sub_chunk_desc);
if (info->save_proc) { if (info->save_proc) {
uint32 extra_data_length = info->save_proc(info, true); uint32 extra_data_length = info->save_proc(info, true);
@@ -264,7 +268,8 @@ static void Save_SLXI()
// write data // write data
info = _sl_xv_sub_chunk_infos; info = _sl_xv_sub_chunk_infos;
for (; info->index != XSLFI_NULL; ++info) { for (; info->index != XSLFI_NULL; ++info) {
if (info->save_version > 0) { uint16 save_version = _sl_xv_feature_versions[info->index];
if (save_version > 0) {
SlxiSubChunkFlags flags = info->flags; SlxiSubChunkFlags flags = info->flags;
assert(!(flags & (XSCF_EXTRA_DATA_PRESENT | XSCF_CHUNK_ID_LIST_PRESENT))); assert(!(flags & (XSCF_EXTRA_DATA_PRESENT | XSCF_CHUNK_ID_LIST_PRESENT)));
uint32 extra_data_length = extra_data_lengths[info->index]; uint32 extra_data_length = extra_data_lengths[info->index];
@@ -272,6 +277,7 @@ static void Save_SLXI()
if (extra_data_length > 0) flags |= XSCF_EXTRA_DATA_PRESENT; if (extra_data_length > 0) flags |= XSCF_EXTRA_DATA_PRESENT;
if (chunk_count > 0) flags |= XSCF_CHUNK_ID_LIST_PRESENT; if (chunk_count > 0) flags |= XSCF_CHUNK_ID_LIST_PRESENT;
SlWriteUint32(flags); SlWriteUint32(flags);
SlWriteUint16(save_version);
SlObject(const_cast<SlxiSubChunkInfo *>(info), _xlsi_sub_chunk_desc); SlObject(const_cast<SlxiSubChunkInfo *>(info), _xlsi_sub_chunk_desc);
if (extra_data_length > 0) { if (extra_data_length > 0) {

View File

@@ -44,6 +44,7 @@ enum SlXvFeatureIndex {
XSLFI_TRAFFIC_LIGHTS, ///< This save game uses road traffic lights XSLFI_TRAFFIC_LIGHTS, ///< This save game uses road traffic lights
XSLFI_RAIL_AGEING, ///< This save game uses the rail aging patch XSLFI_RAIL_AGEING, ///< This save game uses the rail aging patch
XSLFI_SPRINGPP, ///< This is a SpringPP game, use this for loading some settings XSLFI_SPRINGPP, ///< This is a SpringPP game, use this for loading some settings
XSLFI_EXTRA_LARGE_MAP, ///< Extra large map
XSLFI_SIZE, ///< Total count of features, including null feature XSLFI_SIZE, ///< Total count of features, including null feature
}; };

View File

@@ -37,6 +37,9 @@ static void Save_MAPS()
static void Load_MAPS() static void Load_MAPS()
{ {
SlGlobList(_map_dimensions); SlGlobList(_map_dimensions);
if (!ValidateMapSize(_map_dim_x, _map_dim_y)) {
SlErrorCorruptFmt("Invalid map size: %u x %u", _map_dim_x, _map_dim_y);
}
AllocateMap(_map_dim_x, _map_dim_y); AllocateMap(_map_dim_x, _map_dim_y);
} }