ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

stateprovider.h

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the AUTHORS
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef STARK_SERVICES_STATE_PROVIDER_H
00024 #define STARK_SERVICES_STATE_PROVIDER_H
00025 
00026 #include "common/hashmap.h"
00027 #include "common/serializer.h"
00028 #include "common/hash-str.h"
00029 #include "common/stream.h"
00030 #include "common/substream.h"
00031 
00032 #include "math/mathfwd.h"
00033 
00034 #include "engines/stark/resourcereference.h"
00035 
00036 namespace Stark {
00037 
00038 namespace Resources {
00039 class Object;
00040 class Level;
00041 class Location;
00042 }
00043 
00044 class StateReadStream : public Common::SeekableSubReadStream {
00045 public:
00046     explicit StateReadStream(Common::SeekableReadStream *parentStream, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::YES);
00047     virtual ~StateReadStream();
00048 
00049     Common::String readString();
00050 };
00051 
00052 class ResourceSerializer : public Common::Serializer {
00053 public:
00054     ResourceSerializer(Common::SeekableReadStream *in, Common::WriteStream *out, uint32 version);
00055 
00056     void syncAsFloat(float &value);
00057     void syncAsVector3d(Math::Vector3d &value);
00058     void syncAsResourceReference(ResourceReference &reference);
00059     void syncAsString32(Common::String &string);
00060 
00061     template<typename T>
00062     void syncAsResourceReference(T **object, Version minVersion = 0, Version maxVersion = kLastVersion);
00063 
00064     template<typename T>
00065     void syncArraySize(Common::Array<T> &array, Version minVersion = 0, Version maxVersion = kLastVersion);
00066 };
00067 
00068 template<typename T>
00069 void ResourceSerializer::syncAsResourceReference(T **object, Version minVersion, Version maxVersion) {
00070     assert(object);
00071 
00072     if (_version < minVersion || _version > maxVersion)
00073         return; // Ignore anything which is not supposed to be present in this save game version
00074 
00075     if (isLoading()) {
00076         ResourceReference reference;
00077         reference.loadFromStream(_loadStream);
00078         *object = reference.resolve<T>();
00079     } else {
00080         ResourceReference reference;
00081         reference.buildFromResource(*object);
00082         reference.saveToStream(_saveStream);
00083     }
00084 }
00085 
00086 template<typename T>
00087 void ResourceSerializer::syncArraySize(Common::Array<T> &array, Version minVersion, Version maxVersion) {
00088     if (_version < minVersion || _version > maxVersion)
00089         return; // Ignore anything which is not supposed to be present in this save game version
00090 
00091     uint32 size = array.size();
00092     syncAsUint32LE(size);
00093 
00094     if (isLoading()) {
00095         array.resize(size);
00096     }
00097 }
00098 
00104 class StateProvider {
00105 public:
00106     ~StateProvider();
00107 
00108     void restoreLevelState(Resources::Level *level);
00109     void restoreCurrentLevelState(Resources::Level *level);
00110     void restoreLocationState(Resources::Level *level, Resources::Location *location);
00111     void restoreCurrentLocationState(Resources::Level *level, Resources::Location *location);
00112     void restoreGlobalState(Resources::Level *level);
00113 
00114     void saveLevelState(Resources::Level *level);
00115     void saveCurrentLevelState(Resources::Level *level);
00116     void saveLocationState(Resources::Level *level, Resources::Location *location);
00117     void saveCurrentLocationState(Resources::Level *level, Resources::Location *location);
00118     void saveGlobalState(Resources::Level *level);
00119 
00121     void readStateFromStream(StateReadStream *stream, uint saveVersion);
00122 
00124     void writeStateToStream(Common::WriteStream *stream);
00125 
00127     void clear();
00128 
00129     static const uint kMinSaveVersion = 6;
00130     static const uint kSaveVersion = 12;
00131 
00132 private:
00133     class ResourceTreeState {
00134     public:
00135         ResourceTreeState(uint32 size, byte *data, uint32 version);
00136         ~ResourceTreeState();
00137 
00138         uint32 getVersion() const { return _version; }
00139         uint32 getSize() const { return _size; }
00140         byte *getData() const { return _data; }
00141 
00142     private:
00143         uint32 _version;
00144         uint32 _size;
00145         byte *_data;
00146     };
00147 
00148     typedef Common::HashMap<Common::String, ResourceTreeState *> ResourceTreeStateMap;
00149 
00150     void restoreResourceTreeState(const Common::String &storeKey, Resources::Object *root, bool current);
00151     void saveResourceTreeState(const Common::String &storeKey, Resources::Object *root, bool current);
00152 
00153     void readResourceTree(Resources::Object *resource, Common::SeekableReadStream *stream, bool current, uint32 version);
00154     void writeResourceTree(Resources::Object *resource, Common::WriteStream *stream, bool current);
00155 
00156     ResourceTreeStateMap _stateStore;
00157 };
00158 
00159 } // End of namespace Stark
00160 
00161 #endif // STARK_SERVICES_STATE_PROVIDER_H


Generated on Sat Feb 16 2019 05:01:05 for ResidualVM by doxygen 1.7.1
curved edge   curved edge