4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
10 /** @file newgrf_storage.cpp Functionality related to the temporary and persistent storage arrays for NewGRFs. */
13 #include "newgrf_storage.h"
14 #include "core/pool_func.hpp"
15 #include "core/endian_func.hpp"
19 PersistentStoragePool
_persistent_storage_pool("PersistentStorage");
20 INSTANTIATE_POOL_METHODS(PersistentStorage
)
22 /** The changed storage arrays */
23 static std::set
<BasePersistentStorageArray
*> *_changed_storage_arrays
= new std::set
<BasePersistentStorageArray
*>;
26 * Remove references to use.
28 BasePersistentStorageArray::~BasePersistentStorageArray()
30 _changed_storage_arrays
->erase(this);
34 * Add the changed storage array to the list of changed arrays.
35 * This is done so we only have to revert/save the changed
36 * arrays, which saves quite a few clears, etc. after callbacks.
37 * @param storage the array that has changed
39 void AddChangedPersistentStorage(BasePersistentStorageArray
*storage
)
41 _changed_storage_arrays
->insert(storage
);
45 * Clear the changes made since the last #ClearStorageChanges.
46 * This is done for *all* storages that have been registered to with
47 * #AddChangedStorage since the previous #ClearStorageChanges.
49 * This can be done in two ways:
50 * - saving the changes permanently
51 * - reverting to the previous version
52 * @param keep_changes do we save or revert the changes since the last #ClearChanges?
54 void ClearPersistentStorageChanges(bool keep_changes
)
56 /* Loop over all changes arrays */
57 for (std::set
<BasePersistentStorageArray
*>::iterator it
= _changed_storage_arrays
->begin(); it
!= _changed_storage_arrays
->end(); it
++) {
59 DEBUG(desync
, 1, "Discarding persistent storage changes: Feature %d, GrfID %08X, Tile %d", (*it
)->feature
, BSWAP32((*it
)->grfid
), (*it
)->tile
);
61 (*it
)->ClearChanges(keep_changes
);
64 /* And then clear that array */
65 _changed_storage_arrays
->clear();