OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

newgrf_storage.cpp
Go to the documentation of this file.
1 /* $Id: newgrf_storage.cpp 26482 2014-04-23 20:13:33Z rubidium $ */
2
3 /*
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/>.
8 */
9
12 #include "stdafx.h"
13 #include "newgrf_storage.h"
14 #include "core/pool_func.hpp"
15 #include "core/endian_func.hpp"
16 #include "debug.h"
17 #include <set>
18
19 #include "safeguards.h"
20
21 PersistentStoragePool _persistent_storage_pool("PersistentStorage");
22 INSTANTIATE_POOL_METHODS(PersistentStorage)
23
24
25 static std::set<BasePersistentStorageArray*> *_changed_storage_arrays = new std::set<BasePersistentStorageArray*>;
26
27 bool BasePersistentStorageArray::gameloop;
28 bool BasePersistentStorageArray::command;
29 bool BasePersistentStorageArray::testmode;
30
34 BasePersistentStorageArray::~BasePersistentStorageArray()
35 {
36 _changed_storage_arrays->erase(this);
37 }
38
45 void AddChangedPersistentStorage(BasePersistentStorageArray *storage)
46 {
47 _changed_storage_arrays->insert(storage);
48 }
49
57 /* static */ void BasePersistentStorageArray::SwitchMode(PersistentStorageMode mode, bool ignore_prev_mode)
58 {
59 switch (mode) {
60 case PSM_ENTER_GAMELOOP:
61 assert(ignore_prev_mode || !gameloop);
62 assert(!command && !testmode);
63 gameloop = true;
64 break;
65
66 case PSM_LEAVE_GAMELOOP:
67 assert(ignore_prev_mode || gameloop);
68 assert(!command && !testmode);
69 gameloop = false;
70 break;
71
72 case PSM_ENTER_COMMAND:
73 assert((ignore_prev_mode || !command) && !testmode);
74 command = true;
75 break;
76
77 case PSM_LEAVE_COMMAND:
78 assert(ignore_prev_mode || command);
79 command = false;
80 break;
81
82 case PSM_ENTER_TESTMODE:
83 assert(!command && (ignore_prev_mode || !testmode));
84 testmode = true;
85 break;
86
87 case PSM_LEAVE_TESTMODE:
88 assert(ignore_prev_mode || testmode);
89 testmode = false;
90 break;
91
92 default: NOT_REACHED();
93 }
94
95 /* Discard all temporary changes */
96 for (std::set<BasePersistentStorageArray*>::iterator it = _changed_storage_arrays->begin(); it != _changed_storage_arrays->end(); it++) {
97 DEBUG(desync, 1, "Discarding persistent storage changes: Feature %d, GrfID %08X, Tile %d", (*it)->feature, BSWAP32((*it)->grfid), (*it)->tile);
98 (*it)->ClearChanges();
99 }
100 _changed_storage_arrays->clear();
101 }