ScummVM API documentation
archiveloader.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef STARK_SERVICES_ARCHIVE_LOADER_H
23 #define STARK_SERVICES_ARCHIVE_LOADER_H
24 
25 #include "common/list.h"
26 #include "common/str.h"
27 #include "common/substream.h"
28 #include "common/util.h"
29 
30 #include "math/quat.h"
31 #include "math/vector3d.h"
32 
33 #include "engines/stark/formats/xarc.h"
34 #include "engines/stark/resources/object.h"
35 
36 namespace Stark {
37 
38 namespace Resources {
39 class Level;
40 class Location;
41 }
42 
47 public:
48  ArchiveReadStream(Common::SeekableReadStream *parentStream, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::YES);
49  virtual ~ArchiveReadStream();
50 
51  Common::String readString();
52  Common::String readString16();
53  Math::Vector3d readVector3();
54  Math::Quaternion readQuaternion();
55  float readFloat();
56 };
57 
65 
66 public:
67  ~ArchiveLoader();
68 
70  bool load(const Common::Path &archiveName);
71 
73  void unloadUnused();
74 
76  ArchiveReadStream *getFile(const Common::Path &fileName, const Common::Path &archiveName);
77 
79  template <class T>
80  T *useRoot(const Common::Path &archiveName);
81 
83  bool returnRoot(const Common::Path &archiveName);
84 
86  Common::Path buildArchiveName(Resources::Level *level, Resources::Location *location = nullptr) const;
87 
89  Common::SeekableReadStream *getExternalFile(const Common::Path &fileName, const Common::Path &archiveName) const;
90  Common::Path getExternalFilePath(const Common::Path &fileName, const Common::Path &archiveName) const;
91 
92 private:
93  class LoadedArchive {
94  public:
95  explicit LoadedArchive(const Common::Path &archiveName);
96  ~LoadedArchive();
97 
98  const Common::Path &getFilename() const { return _filename; }
99  const Formats::XARCArchive &getXArc() const { return _xarc; }
100  Resources::Object *getRoot() const { return _root; }
101 
102  void importResources();
103 
104  bool isInUse() const { return _useCount > 0; }
105  void incUsage() { _useCount++; }
106  void decUsage() { _useCount = MAX<int>(_useCount - 1, 0); }
107 
108  private:
109  uint _useCount;
110  Common::Path _filename;
111  Formats::XARCArchive _xarc;
112  Resources::Object *_root;
113  };
114 
116 
117  bool hasArchive(const Common::Path &archiveName) const;
118  LoadedArchive *findArchive(const Common::Path &archiveName) const;
119 
120  LoadedArchiveList _archives;
121 };
122 
123 template <class T>
124 T *ArchiveLoader::useRoot(const Common::Path &archiveName) {
125  LoadedArchive *archive = findArchive(archiveName);
126  archive->incUsage();
127  return Resources::Object::cast<T>(archive->getRoot());
128 }
129 
130 } // End of namespace Stark
131 
132 #endif // STARK_SERVICES_ARCHIVE_LOADER_H
Definition: location.h:51
Definition: str.h:59
T * useRoot(const Common::Path &archiveName)
Definition: archiveloader.h:124
Definition: path.h:52
Definition: stream.h:745
Definition: archiveloader.h:64
Definition: xarc.h:33
Definition: console.h:27
Definition: object.h:143
Definition: substream.h:78
Definition: level.h:39
Definition: archiveloader.h:46