ScummVM API documentation
cif.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 NANCY_CIF_H
23 #define NANCY_CIF_H
24 
25 #include "common/archive.h"
26 #include "common/rect.h"
27 #include "common/hashmap.h"
28 
29 namespace Common {
30 class SeekableReadStream;
31 class Serializer;
32 }
33 
34 namespace Nancy {
35 
36 struct CifInfo {
37  enum ResType : byte {
38  kResTypeAny,
39  // Type 1 seems to be obsolete
40  kResTypeImage = 2,
41  kResTypeScript = 3,
42  kResTypeEmpty = 4
43  };
44 
45  enum ResCompression {
46  kResCompressionNone = 1,
47  kResCompression = 2
48  };
49 
50  Common::Path name;
51  ResType type = kResTypeEmpty; // ResType
52  ResCompression comp = kResCompressionNone; // ResCompression
53  uint16 width = 0, pitch = 0, height = 0;
54  byte depth = 0; // Bit depth
55  uint32 compressedSize = 0, size = 0;
56  Common::Rect src, dest; // Used when drawing conversation cels
57 
58  uint32 dataOffset = 0;
59 };
60 
61 // Wrapper for a single file. Exclusively used for scene IFFs, though it can contain anything.
62 class CifFile {
63 public:
64  CifFile() : _stream(nullptr) {}
65  CifFile(const CifInfo &info) : _stream(nullptr), _info(info) {}
66  CifFile(Common::SeekableReadStream *stream, const Common::Path &name);
67  ~CifFile();
68 
69  Common::SeekableReadStream *createReadStream() const;
70  Common::SeekableReadStream *createReadStreamRaw() const;
71  bool sync(Common::Serializer &ser);
72  CifInfo getInfo() const { return _info; }
73 
74 private:
76  CifInfo _info;
77 };
78 
79 // Container type comprising of multiple CIF files. Contrary to its name it contains no tree structure.
80 class CifTree : public Common::Archive {
81 public:
82  CifTree() : _stream(nullptr) {}
83  CifTree(Common::SeekableReadStream *stream, const Common::Path &name);
84  virtual ~CifTree();
85 
86  // Used for extracting additional image data for conversation cels (nancy2 and up)
87  const CifInfo &getCifInfo(const Common::Path &name) const;
88 
89  // Archive interface
90  bool hasFile(const Common::Path &path) const override;
91  int listMembers(Common::ArchiveMemberList &list) const override;
92 
93  const Common::ArchiveMemberPtr getMember(const Common::Path &path) const override;
94  Common::SeekableReadStream *createReadStreamForMember(const Common::Path &path) const override;
95 
96  Common::Path getName() const { return _name; }
97 
98  static CifTree *makeCifTreeArchive(const Common::String &name, const Common::String &ext);
99  Common::SeekableReadStream *createReadStreamRaw(const Common::Path &path) const;
100  bool sync(Common::Serializer &ser);
101 
102  void addInfo(const CifInfo &info) { _writeFileMap.push_back(info); }
103  uint writeFileMapSize() const { return _writeFileMap.size(); }
104  uint32 getDataOffset(uint i) const { return _writeFileMap[i].dataOffset; }
105  void setDataOffset(uint i, uint32 offset) { _writeFileMap[i].dataOffset = offset; }
106 
107  Common::Array<Common::Path> getPathsForType(CifInfo::ResType type = CifInfo::kResTypeAny) const;
108 
109 private:
110  Common::Path _name;
113  Common::Array<CifInfo> _writeFileMap;
114 };
115 
116 // Ciftree that only provides a file if a certain ConfMan flag is true. Used for handling game patches
117 class PatchTree : public CifTree {
118 public:
119  PatchTree(Common::SeekableReadStream *stream, const Common::Path &name) : CifTree(stream, name) {}
120  virtual ~PatchTree() {}
121 
122  bool hasFile(const Common::Path &path) const override;
123 
125 };
126 
127 } // End of namespace Nancy
128 
129 #endif // NANCY_CIF_H
Definition: str.h:59
Definition: cif.h:62
Definition: list.h:44
Definition: rect.h:524
Definition: path.h:52
Definition: cif.h:117
Definition: stream.h:745
Definition: serializer.h:80
Definition: archive.h:141
Definition: hashmap.h:85
Definition: cif.h:80
Definition: algorithm.h:29
Definition: cif.h:36
Definition: actionmanager.h:32