2016-09-18 18:48:52 +00:00
|
|
|
/*
|
|
|
|
* 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 {
|
2024-01-07 16:41:53 +00:00
|
|
|
uint32_t length;
|
2016-09-18 18:48:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const SaveLoad _long_bridge_signal_storage_stub_desc[] = {
|
|
|
|
SLE_VAR(LongBridgeSignalStorageStub, length, SLE_UINT32),
|
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
2021-10-02 15:45:02 +00:00
|
|
|
SlArray(lbss.signal_red_bits.data(), stub.length, SLE_UINT64);
|
2016-09-18 18:48:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void RealSave_XBSS(const LongBridgeSignalStorage *lbss)
|
|
|
|
{
|
|
|
|
LongBridgeSignalStorageStub stub;
|
2024-01-07 16:41:53 +00:00
|
|
|
stub.length = (uint32_t)lbss->signal_red_bits.size();
|
2016-09-18 18:48:52 +00:00
|
|
|
SlObject(&stub, _long_bridge_signal_storage_stub_desc);
|
2024-01-07 16:41:53 +00:00
|
|
|
SlArray(const_cast<uint64_t*>(lbss->signal_red_bits.data()), stub.length, SLE_UINT64);
|
2016-09-18 18:48:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-18 22:37:35 +00:00
|
|
|
static void Load_XBST()
|
|
|
|
{
|
2024-01-07 16:41:53 +00:00
|
|
|
size_t count = SlGetFieldLength() / sizeof(uint32_t);
|
2022-06-18 22:37:35 +00:00
|
|
|
for (size_t i = 0; i < count; i++) {
|
|
|
|
_bridge_signal_style_map.insert(SlReadUint32());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void Save_XBST()
|
|
|
|
{
|
2024-01-07 16:41:53 +00:00
|
|
|
SlSetLength(_bridge_signal_style_map.size() * sizeof(uint32_t));
|
|
|
|
for (uint32_t val : _bridge_signal_style_map) {
|
2022-06-18 22:37:35 +00:00
|
|
|
SlWriteUint32(val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-25 17:10:15 +00:00
|
|
|
extern const ChunkHandler bridge_signal_chunk_handlers[] = {
|
|
|
|
{ 'XBSS', Save_XBSS, Load_XBSS, nullptr, nullptr, CH_SPARSE_ARRAY },
|
2022-06-18 22:37:35 +00:00
|
|
|
{ 'XBST', Save_XBST, Load_XBST, nullptr, nullptr, CH_RIFF },
|
2016-09-18 18:48:52 +00:00
|
|
|
};
|
2021-10-25 17:10:15 +00:00
|
|
|
|
|
|
|
extern const ChunkHandlerTable _bridge_signal_chunk_handlers(bridge_signal_chunk_handlers);
|