Extend bridge signal simulation to support an unlimited no. of signals.

This is instead of the previous limit of 16, all stored in M2.
This commit is contained in:
Jonathan G Rennison
2016-09-18 19:48:52 +01:00
parent 61500b596e
commit 556594f2f0
18 changed files with 321 additions and 57 deletions

View File

@@ -0,0 +1,58 @@
/* $Id$ */
/*
* 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 bridge_signal_sl.cpp Code handling saving and loading of data for signal on bridges */
#include "../stdafx.h"
#include "../bridge_signal_map.h"
#include "saveload.h"
#include <vector>
/** stub save header struct */
struct LongBridgeSignalStorageStub {
uint32 length;
};
static const SaveLoad _long_bridge_signal_storage_stub_desc[] = {
SLE_VAR(LongBridgeSignalStorageStub, length, SLE_UINT32),
SLE_END()
};
static void Load_XBSS()
{
int index;
LongBridgeSignalStorageStub stub;
while ((index = SlIterateArray()) != -1) {
LongBridgeSignalStorage &lbss = _long_bridge_signal_sim_map[index];
SlObject(&stub, _long_bridge_signal_storage_stub_desc);
lbss.signal_red_bits.resize(stub.length);
SlArray(&(lbss.signal_red_bits[0]), stub.length, SLE_UINT64);
}
}
static void RealSave_XBSS(const LongBridgeSignalStorage *lbss)
{
LongBridgeSignalStorageStub stub;
stub.length = lbss->signal_red_bits.size();
SlObject(&stub, _long_bridge_signal_storage_stub_desc);
SlArray(const_cast<uint64*>(&(lbss->signal_red_bits[0])), stub.length, SLE_UINT64);
}
static void Save_XBSS()
{
for (const auto &it : _long_bridge_signal_sim_map) {
const LongBridgeSignalStorage &lbss = it.second;
SlSetArrayIndex(it.first);
SlAutolength((AutolengthProc*) RealSave_XBSS, const_cast<LongBridgeSignalStorage*>(&lbss));
}
}
extern const ChunkHandler _bridge_signal_chunk_handlers[] = {
{ 'XBSS', Save_XBSS, Load_XBSS, NULL, NULL, CH_SPARSE_ARRAY | CH_LAST},
};

View File

@@ -45,7 +45,7 @@ std::vector<uint32> _sl_xv_discardable_chunk_ids; ///< list of chunks
static const uint32 _sl_xv_slxi_chunk_version = 0; ///< current version os SLXI chunk
const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
{ XSLFI_SIG_TUNNEL_BRIDGE, XSCF_NULL, 3, 3, "signal_tunnel_bridge", NULL, NULL, NULL },
{ XSLFI_SIG_TUNNEL_BRIDGE, XSCF_NULL, 4, 4, "signal_tunnel_bridge", NULL, NULL, "XBSS" },
{ XSLFI_NULL, XSCF_NULL, 0, 0, NULL, NULL, NULL, NULL },// This is the end marker
};

View File

@@ -457,6 +457,7 @@ extern const ChunkHandler _linkgraph_chunk_handlers[];
extern const ChunkHandler _airport_chunk_handlers[];
extern const ChunkHandler _object_chunk_handlers[];
extern const ChunkHandler _persistent_storage_chunk_handlers[];
extern const ChunkHandler _bridge_signal_chunk_handlers[];
/** Array of all chunks in a savegame, \c NULL terminated. */
static const ChunkHandler * const _chunk_handlers[] = {
@@ -494,6 +495,7 @@ static const ChunkHandler * const _chunk_handlers[] = {
_airport_chunk_handlers,
_object_chunk_handlers,
_persistent_storage_chunk_handlers,
_bridge_signal_chunk_handlers,
NULL,
};