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

archiveloader.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_ARCHIVE_LOADER_H
00024 #define STARK_SERVICES_ARCHIVE_LOADER_H
00025 
00026 #include "common/list.h"
00027 #include "common/str.h"
00028 #include "common/substream.h"
00029 #include "common/util.h"
00030 
00031 #include "math/quat.h"
00032 #include "math/vector3d.h"
00033 
00034 #include "engines/stark/formats/xarc.h"
00035 #include "engines/stark/resources/object.h"
00036 
00037 namespace Stark {
00038 
00039 namespace Resources {
00040 class Level;
00041 class Location;
00042 }
00043 
00047 class ArchiveReadStream : public Common::SeekableSubReadStream {
00048 public:
00049     ArchiveReadStream(Common::SeekableReadStream *parentStream, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::YES);
00050     virtual ~ArchiveReadStream();
00051 
00052     Common::String readString();
00053     Common::String readString16();
00054     Math::Vector3d readVector3();
00055     Math::Quaternion readQuaternion();
00056     float readFloat();
00057 };
00058 
00065 class ArchiveLoader {
00066 
00067 public:
00068     ~ArchiveLoader();
00069 
00071     bool load(const Common::String &archiveName);
00072 
00074     void unloadUnused();
00075 
00077     ArchiveReadStream *getFile(const Common::String &fileName, const Common::String &archiveName);
00078 
00080     template <class T>
00081     T *useRoot(const Common::String &archiveName);
00082 
00084     bool returnRoot(const Common::String &archiveName);
00085 
00087     Common::String buildArchiveName(Resources::Level *level, Resources::Location *location = nullptr) const;
00088 
00090     Common::SeekableReadStream *getExternalFile(const Common::String &fileName, const Common::String &archiveName) const;
00091     Common::String getExternalFilePath(const Common::String &fileName, const Common::String &archiveName) const;
00092 
00093 private:
00094     class LoadedArchive {
00095     public:
00096         explicit LoadedArchive(const Common::String &archiveName);
00097         ~LoadedArchive();
00098 
00099         const Common::String &getFilename() const { return _filename; }
00100         const Formats::XARCArchive &getXArc() const { return _xarc; }
00101         Resources::Object *getRoot() const { return _root; }
00102 
00103         void importResources();
00104 
00105         bool isInUse() const { return _useCount > 0; }
00106         void incUsage() { _useCount++; }
00107         void decUsage() { _useCount = MAX<int>(_useCount - 1, 0); }
00108 
00109     private:
00110         uint _useCount;
00111         Common::String _filename;
00112         Formats::XARCArchive _xarc;
00113         Resources::Object *_root;
00114     };
00115 
00116     typedef Common::List<LoadedArchive *> LoadedArchiveList;
00117 
00118     bool hasArchive(const Common::String &archiveName) const;
00119     LoadedArchive *findArchive(const Common::String &archiveName) const;
00120 
00121     LoadedArchiveList _archives;
00122 };
00123 
00124 template <class T>
00125 T *ArchiveLoader::useRoot(const Common::String &archiveName) {
00126     LoadedArchive *archive = findArchive(archiveName);
00127     archive->incUsage();
00128     return Resources::Object::cast<T>(archive->getRoot());
00129 }
00130 
00131 } // End of namespace Stark
00132 
00133 #endif // STARK_SERVICES_ARCHIVE_LOADER_H


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