storage_sl.cpp

Go to the documentation of this file.
00001 /* $Id: storage_sl.cpp 26371 2014-02-23 22:03:08Z 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 "saveload.h"
00015 
00017 static const SaveLoad _storage_desc[] = {
00018    SLE_CONDVAR(PersistentStorage, grfid,    SLE_UINT32,                  6, SL_MAX_VERSION),
00019    SLE_CONDARR(PersistentStorage, storage,  SLE_UINT32, 16,            161, SL_MAX_VERSION),
00020    SLE_END()
00021 };
00022 
00024 static void Load_PSAC()
00025 {
00026   int index;
00027 
00028   while ((index = SlIterateArray()) != -1) {
00029     assert(PersistentStorage::CanAllocateItem());
00030     PersistentStorage *ps = new (index) PersistentStorage(0, 0, 0);
00031     SlObject(ps, _storage_desc);
00032   }
00033 }
00034 
00036 static void Save_PSAC()
00037 {
00038   PersistentStorage *ps;
00039 
00040   /* Write the industries */
00041   FOR_ALL_STORAGES(ps) {
00042     ps->ClearChanges();
00043     SlSetArrayIndex(ps->index);
00044     SlObject(ps, _storage_desc);
00045   }
00046 }
00047 
00049 extern const ChunkHandler _persistent_storage_chunk_handlers[] = {
00050   { 'PSAC', Save_PSAC, Load_PSAC, NULL, NULL, CH_ARRAY | CH_LAST},
00051 };