ScummVM API documentation
datafile.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 MEDIASTATION_DATAFILE_H
23 #define MEDIASTATION_DATAFILE_H
24 
25 #include "common/file.h"
26 #include "common/stream.h"
27 #include "common/path.h"
28 #include "common/rect.h"
29 #include "common/str.h"
30 
31 namespace MediaStation {
32 
33 // The version number of this engine,
34 // in the form 4.0r8 (major . minor r revision).
35 struct VersionInfo {
36  uint16 major = 0;
37  uint16 minor = 0;
38  uint16 patch = 0;
39 };
40 
42 
43 // A Media Station datafile consists of one or more RIFF-style "subfiles". Aside
44 // from some oddness at the start of the subfile, each subfile is basically
45 // standard sequence of chunks inside a LIST chunk, like you'd see in any RIFF
46 // file. These chunks have special IDs:
47 // - igod: Indicates a chunk that contains metadata about actor(s) in metadata sections.
48 // - a000, where 000 is a string that represents a 3-digit hexadecimal number.
49 // Indicates a chunk that contains actor data (sounds and bitmaps).
50 
51 enum DatumType {
52  kDatumTypeEmpty = 0x00,
53  kDatumTypeUint8 = 0x02,
54  kDatumTypeUint16 = 0x03,
55  kDatumTypeUint32 = 0x04,
56  kDatumTypeInt8 = 0x05,
57  kDatumTypeInt16 = 0x06,
58  kDatumTypeInt32 = 0x07,
59  kDatumTypeFloat = 0x08,
60  kDatumTypeDouble = 0x09,
61  kDatumTypeFilename = 0x0a,
62  kDatumTypeRect = 0x0d,
63  kDatumTypePoint = 0x0e,
64  kDatumTypeGraphicSize = 0x0f,
65  kDatumTypeGraphicUnit = 0x10,
66  kDatumTypeTime = 0x11,
67  kDatumTypeString = 0x12,
68  kDatumTypeVersion = 0x13,
69  kDatumTypeChunkReference = 0x1b,
70  kDatumTypePolygon = 0x1d,
71 };
72 
74 public:
75  // Data files are internally little-endian, even on game versions targeting
76  // big-endian systems. The original engine has code for swapping byte order
77  // at runtime when needed. All of these internally assume the data files are
78  // stored little-endian on disk.
79  byte readTypedByte();
80  uint16 readTypedUint16();
81  uint32 readTypedUint32();
82  int8 readTypedSByte();
83  int16 readTypedSint16();
84  int32 readTypedSint32();
85  float readTypedFloat();
86  double readTypedDouble();
87  Common::String readTypedFilename();
88  Common::Rect readTypedRect();
89  Common::Point readTypedPoint();
90  Common::Point readTypedGraphicSize();
91  int16 readTypedGraphicUnit();
92  double readTypedTime();
93  Common::String readTypedString();
94  VersionInfo readTypedVersion();
95  uint32 readTypedChunkReference();
96  Polygon readTypedPolygon();
97 
98 private:
99  void readAndVerifyType(DatumType type);
100 };
101 
102 class Chunk : public ParameterReadStream {
103 public:
104  Chunk() = default;
106 
107  uint32 bytesRemaining();
108 
109  uint32 _id = 0;
110  uint32 _length = 0;
111 
112  // ReadStream implementation
113  virtual bool eos() const { return _parentStream->eos(); };
114  virtual bool err() const { return _parentStream->err(); };
115  virtual void clearErr() { _parentStream->clearErr(); };
116  virtual uint32 read(void *dataPtr, uint32 dataSize);
117  virtual int64 pos() const { return _parentStream->pos(); };
118  virtual int64 size() const { return _parentStream->size(); };
119  virtual bool skip(uint32 offset) { return seek(offset, SEEK_CUR); };
120  virtual bool seek(int64 offset, int whence = SEEK_SET);
121 
122 private:
123  Common::SeekableReadStream *_parentStream = nullptr;
124  uint32 _dataStartOffset = 0;
125  uint32 _dataEndOffset = 0;
126 };
127 
128 class Subfile {
129 public:
130  Subfile() = default;
132 
133  Chunk nextChunk();
134  bool atEnd();
135 
136  Chunk _currentChunk;
137  uint32 _rate;
138 
139 private:
140  Common::SeekableReadStream *_stream = nullptr;
141  Chunk _rootChunk;
142 };
143 
144 class Datafile : public Common::File {
145 public:
146  Datafile(const Common::Path &path);
147 
148  Subfile getNextSubfile();
149 };
150 
151 } // End of namespace MediaStation
152 
153 #endif
virtual void clearErr()
Definition: datafile.h:115
virtual int64 size() const
Definition: datafile.h:118
Definition: datafile.h:35
Definition: str.h:59
Definition: datafile.h:144
virtual bool eos() const
Definition: datafile.h:113
Definition: actor.h:33
Definition: datafile.h:102
virtual int64 pos() const
Definition: datafile.h:117
Definition: rect.h:524
Definition: path.h:52
Definition: stream.h:745
Definition: file.h:47
virtual bool skip(uint32 offset)
Definition: datafile.h:119
Definition: rect.h:144
Definition: datafile.h:128
virtual bool err() const
Definition: datafile.h:114
Definition: datafile.h:73