newgrf_storage.cpp

Go to the documentation of this file.
00001 /* $Id: newgrf_storage.cpp 26175 2013-12-23 18:09:29Z frosch $ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * 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.
00006  * 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.
00007  * 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/>.
00008  */
00009 
00012 #include "stdafx.h"
00013 #include "newgrf_storage.h"
00014 #include "core/pool_func.hpp"
00015 #include "core/endian_func.hpp"
00016 #include "debug.h"
00017 #include <set>
00018 
00019 PersistentStoragePool _persistent_storage_pool("PersistentStorage");
00020 INSTANTIATE_POOL_METHODS(PersistentStorage)
00021 
00022 
00023 static std::set<BasePersistentStorageArray*> *_changed_storage_arrays = new std::set<BasePersistentStorageArray*>;
00024 
00028 BasePersistentStorageArray::~BasePersistentStorageArray()
00029 {
00030   _changed_storage_arrays->erase(this);
00031 }
00032 
00039 void AddChangedPersistentStorage(BasePersistentStorageArray *storage)
00040 {
00041   _changed_storage_arrays->insert(storage);
00042 }
00043 
00054 void ClearPersistentStorageChanges(bool keep_changes)
00055 {
00056   /* Loop over all changes arrays */
00057   for (std::set<BasePersistentStorageArray*>::iterator it = _changed_storage_arrays->begin(); it != _changed_storage_arrays->end(); it++) {
00058     if (!keep_changes) {
00059       DEBUG(desync, 1, "Discarding persistent storage changes: Feature %d, GrfID %08X, Tile %d", (*it)->feature, BSWAP32((*it)->grfid), (*it)->tile);
00060     }
00061     (*it)->ClearChanges(keep_changes);
00062   }
00063 
00064   /* And then clear that array */
00065   _changed_storage_arrays->clear();
00066 }