Merge branch 'master' into jgrpp
Bump savegame for water regions for ship pathfinder Use ring_buffer for ShipPathCache
This commit is contained in:
@@ -37,4 +37,5 @@ add_files(
|
||||
subsidy_sl.cpp
|
||||
town_sl.cpp
|
||||
vehicle_sl.cpp
|
||||
water_regions_sl.cpp
|
||||
)
|
||||
|
@@ -74,6 +74,7 @@
|
||||
#include "../newgrf_industrytiles.h"
|
||||
#include "../timer/timer.h"
|
||||
#include "../timer/timer_game_tick.h"
|
||||
#include "../pathfinder/water_regions.h"
|
||||
|
||||
|
||||
#include "../sl/saveload_internal.h"
|
||||
@@ -4398,6 +4399,8 @@ bool AfterLoadGame()
|
||||
c->settings = _settings_client.company;
|
||||
}
|
||||
|
||||
if (IsSavegameVersionBefore(SLV_WATER_REGIONS) && SlXvIsFeatureMissing(XSLFI_WATER_REGIONS)) InitializeWaterRegions();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@@ -115,6 +115,7 @@ static const std::vector<ChunkHandlerRef> &ChunkHandlers()
|
||||
extern const ChunkHandlerTable _airport_chunk_handlers;
|
||||
extern const ChunkHandlerTable _object_chunk_handlers;
|
||||
extern const ChunkHandlerTable _persistent_storage_chunk_handlers;
|
||||
extern const ChunkHandlerTable _water_region_chunk_handlers;
|
||||
|
||||
/** List of all chunks in a savegame. */
|
||||
static const ChunkHandlerTable _chunk_handler_tables[] = {
|
||||
@@ -152,6 +153,7 @@ static const std::vector<ChunkHandlerRef> &ChunkHandlers()
|
||||
_airport_chunk_handlers,
|
||||
_object_chunk_handlers,
|
||||
_persistent_storage_chunk_handlers,
|
||||
_water_region_chunk_handlers,
|
||||
};
|
||||
|
||||
static std::vector<ChunkHandlerRef> _chunk_handlers;
|
||||
|
@@ -309,13 +309,9 @@ public:
|
||||
if (v->type != VEH_SHIP) return;
|
||||
SlObject(v, this->GetLoadDescription());
|
||||
|
||||
if (!_path_td.empty() && _path_td.size() <= SHIP_PATH_CACHE_LENGTH) {
|
||||
if (!_path_td.empty()) {
|
||||
Ship *s = Ship::From(v);
|
||||
s->cached_path.reset(new ShipPathCache());
|
||||
s->cached_path->count = (uint8_t)_path_td.size();
|
||||
for (size_t i = 0; i < _path_td.size(); i++) {
|
||||
s->cached_path->td[i] = _path_td[i];
|
||||
}
|
||||
s->cached_path.insert(s->cached_path.end(), _path_td.begin(), _path_td.end());
|
||||
}
|
||||
_path_td.clear();
|
||||
}
|
||||
|
58
src/saveload/water_regions_sl.cpp
Normal file
58
src/saveload/water_regions_sl.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* This file is part of OpenTTD.
|
||||
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
||||
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file water_regions_sl.cpp Handles saving and loading of water region data */
|
||||
|
||||
#include "../stdafx.h"
|
||||
|
||||
#include "saveload.h"
|
||||
#include "../pathfinder/water_regions.h"
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
namespace upstream_sl {
|
||||
|
||||
static const SaveLoad _water_region_desc[] = {
|
||||
SLE_VAR(WaterRegionSaveLoadInfo, initialized, SLE_BOOL),
|
||||
};
|
||||
|
||||
struct WRGNChunkHandler : ChunkHandler {
|
||||
WRGNChunkHandler() : ChunkHandler('WRGN', CH_TABLE) {}
|
||||
|
||||
void Save() const override
|
||||
{
|
||||
SlTableHeader(_water_region_desc);
|
||||
|
||||
int index = 0;
|
||||
for (WaterRegionSaveLoadInfo ®ion : GetWaterRegionSaveLoadInfo()) {
|
||||
SlSetArrayIndex(index++);
|
||||
SlObject(®ion, _water_region_desc);
|
||||
}
|
||||
}
|
||||
|
||||
void Load() const override
|
||||
{
|
||||
const std::vector<SaveLoad> slt = SlTableHeader(_water_region_desc);
|
||||
|
||||
int index;
|
||||
|
||||
std::vector<WaterRegionSaveLoadInfo> loaded_info;
|
||||
while ((index = SlIterateArray()) != -1) {
|
||||
WaterRegionSaveLoadInfo region_info;
|
||||
SlObject(®ion_info, slt);
|
||||
loaded_info.push_back(std::move(region_info));
|
||||
}
|
||||
|
||||
LoadWaterRegions(loaded_info);
|
||||
}
|
||||
};
|
||||
|
||||
static const WRGNChunkHandler WRGN;
|
||||
static const ChunkHandlerRef water_region_chunk_handlers[] = { WRGN };
|
||||
extern const ChunkHandlerTable _water_region_chunk_handlers(water_region_chunk_handlers);
|
||||
|
||||
}
|
Reference in New Issue
Block a user