ScummVM API documentation
hresmgr.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  * aint32 with this program; if not, write to the Free Software
19  *
20  *
21  * Based on the original sources
22  * Faery Tale II -- The Halls of the Dead
23  * (c) 1993-1996 The Wyrmkeep Entertainment Co.
24  */
25 
26 #ifndef SAGA2_HRESMGR_H
27 #define SAGA2_HRESMGR_H
28 
29 #include "common/file.h"
30 
31 namespace Saga2 {
32 
33 
34 #define USE_MEMORY_MAPPED_FILES 0
35 
36 /* ===================================================================== *
37  Constants and common types
38  * ===================================================================== */
39 
40 typedef uint32 hResID;
41 typedef Common::HashMap<int16, byte*> DataMap;
42 
43 #define BAD_ID ((hResID)0xFFFFFFFFL)
44 #define NATURAL_SIZE ((hResID)0xFFFFFFFFL)
45 
46 struct hResEntry;
47 class hResContext;
48 class hResource;
49 
50 /* ===================================================================== *
51  hResEntry struct
52  * ===================================================================== */
53 
54 struct hResEntry {
55  hResID id; // id of this entry or BAD_ID
56  uint32 offset; // offset in file
57  uint32 size; // size in file
58 public:
59 
60  hResEntry() {
61  id = BAD_ID;
62  size = 0;
63  offset = 0;
64  }
65 
66  void use() {
67  size += 0x01000000L;
68  }
69  void abandon() {
70  size -= 0x01000000L;
71  }
72  uint8 useCount() {
73  return size >> 24;
74  }
75  bool isUsed() {
76  return ((size & 0xFF000000L) != 0L);
77  }
78 
79  bool isExternal() {
80  return ((offset & (1L << 31)) != 0L);
81  }
82 
83  uint32 resOffset() {
84  return (offset & 0x0FFFFFFFL);
85  }
86  uint32 resSize() {
87  return (size & 0x00FFFFFF);
88  }
89 };
90 
91 
92 
93 /* ===================================================================== *
94  Resource Context
95  * ===================================================================== */
96 
97 
98 class hResContext {
99 
100 protected:
101  uint16 _numEntries;
102  hResource *_res;
103  hResContext *_parent;
104  hResEntry *_base;
105  DataMap _indexData; // allocated array of handles
106  Common::File _file;
107  Common::File *_handle;
108  uint32 _bytecount;
109  uint32 _bytepos;
110 
111  hResEntry *findEntry(hResID id);
112 
113 public:
114  bool _valid;
115  Common::Path _filename;
116 
117  hResContext();
118  hResContext(hResContext *sire, hResID id, const char []);
119  virtual ~hResContext();
120 
121  uint32 getResID() {
122  return _base->id;
123  }
124 
125  uint32 size(hResID id);
126  uint32 count();
127  uint32 count(hResID id);
128  bool seek(hResID id);
129  void rest();
130  uint32 readbytes(void *buffer, uint32 size);
131  bool eor();
132  inline size_t bytesleft() {
133  return _bytecount;
134  }
135 
136  bool read(void *buffer, uint32 size);
137  bool skip(uint32 amount);
138  bool get(hResID id, void *buffer, uint32 size);
139  uint32 getSize(hResID id, const char desc[]);
140  byte *loadResource(hResID id, const char desc[], const Common::Path &filename = Common::Path());
141  byte *loadIndexResource(int16 index, const char desc[], const Common::Path &filename = Common::Path());
142  void releaseIndexData();
143  Common::File *resFileHandle() {
144  return _handle;
145  }
146 };
147 
148 /* ===================================================================== *
149  Resource file
150  * ===================================================================== */
151 
152 class hResource : public hResContext {
153 
154  friend class hResContext;
155 
156  uint32 _firstGroupOffset;
157  hResEntry *_table;
158 
159 public:
160  hResource(const char *resname);
161  virtual ~hResource();
162 
163  hResContext *newContext(hResID id, const char []);
164  void disposeContext(hResContext *con);
165  void readEntry(hResEntry &element);
166  void readResource(hResEntry &element);
167 };
168 
169 #define HRES_ID MKTAG('H','R','E','S')
170 
171 
172 } // end of namespace Saga2
173 
174 #endif
Definition: actor.h:32
Definition: path.h:52
Definition: hresmgr.h:98
Definition: hresmgr.h:152
Definition: file.h:47
Definition: hresmgr.h:54