ScummVM API documentation
resource.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 SCUMM_RESOURCE_H
23 #define SCUMM_RESOURCE_H
24 
25 #include "common/array.h"
26 #include "scumm/scumm.h" // for ResType
27 
28 namespace Scumm {
29 
30 enum {
31  OF_OWNER_MASK = 0x0F,
32  OF_STATE_MASK = 0xF0,
33 
34  OF_STATE_SHL = 4
35 };
36 
38  uint32 _size;
39  uint32 _pos;
40  const byte *_ptr;
41  bool _smallHeader;
42 public:
43  ResourceIterator(const byte *searchin, bool smallHeader);
44  const byte *findNext(uint32 tag);
45 };
46 
47 enum : uint {
48  RES_INVALID_OFFSET = 0xFFFFFFFF
49 };
50 
51 class ScummEngine;
52 
69 };
70 
76  //friend class ScummDebugger;
77  //friend class ScummEngine;
78 protected:
79  ScummEngine *_vm;
80 
81 public:
82  class Resource {
83  public:
87  byte *_address;
88 
92  uint32 _size;
93 
94  protected:
104  byte _flags;
105 
110  byte _status;
111 
112  public:
116  byte _roomno;
117 
126  uint32 _roomoffs;
127 
128  public:
129  Resource();
130  ~Resource();
131 
132  void nuke();
133 
134  inline void setResourceCounter(byte counter);
135  inline byte getResourceCounter() const;
136 
137  void lock();
138  void unlock();
139  bool isLocked() const;
140 
141  // HE specific
142  void setModified();
143  bool isModified() const;
144  void setOffHeap();
145  void setOnHeap();
146  bool isOffHeap() const;
147  };
148 
152  class ResTypeData : public Common::Array<Resource> {
153  friend class ResourceManager;
154  public:
159 
165  uint32 _tag;
166 
167  public:
168  ResTypeData();
169  ~ResTypeData();
170  };
171  ResTypeData _types[rtLast + 1];
172 
173 protected:
174  uint32 _allocatedSize;
175  uint32 _maxHeapThreshold, _minHeapThreshold;
176  byte _expireCounter;
177 
178 public:
180  ~ResourceManager();
181 
182  void setHeapThreshold(int min, int max);
183  uint32 getHeapSize() { return _allocatedSize; }
184 
185  void allocResTypeData(ResType type, uint32 tag, int num, ResTypeMode mode);
186  void freeResources();
187 
188  byte *createResource(ResType type, ResId idx, uint32 size);
189  void nukeResource(ResType type, ResId idx);
190 
191 // inline Resource &getRes(ResType type, ResId idx) { return _types[type][idx]; }
192 // inline const Resource &getRes(ResType type, ResId idx) const { return _types[type][idx]; }
193 
194  bool isResourceLoaded(ResType type, ResId idx) const;
195 
196  void lock(ResType type, ResId idx);
197  void unlock(ResType type, ResId idx);
198  bool isLocked(ResType type, ResId idx) const;
199 
200  // HE Specific
201  void setModified(ResType type, ResId idx);
202  bool isModified(ResType type, ResId idx) const;
203  void setOffHeap(ResType type, ResId idx);
204  bool isOffHeap(ResType type, ResId idx) const;
205  void setOnHeap(ResType type, ResId idx);
206 
212  void increaseExpireCounter();
213 
217  void setResourceCounter(ResType type, ResId idx, byte counter);
218 
225  void increaseResourceCounters();
226 
227  void resourceStats();
228 
229 //protected:
230  bool validateResource(const char *str, ResType type, ResId idx) const;
231 protected:
232  void expireResources(uint32 size);
233 };
234 
235 } // End of namespace Scumm
236 
237 #endif
ResTypeMode _mode
Definition: resource.h:158
Resource comes from data files, does not change.
Definition: resource.h:67
uint32 _roomoffs
Definition: resource.h:126
Definition: array.h:52
Definition: resource.h:37
Definition: resource.h:75
ResType
Definition: scumm.h:256
Definition: scumm.h:518
byte _flags
Definition: resource.h:104
Definition: resource.h:82
uint32 _tag
Definition: resource.h:165
byte _status
Definition: resource.h:110
byte _roomno
Definition: resource.h:116
byte * _address
Definition: resource.h:87
uint32 _size
Definition: resource.h:92
ResTypeMode
Definition: resource.h:65
Definition: resource.h:152
Resource is generated during runtime and may change.
Definition: resource.h:66
Resource comes from data files, but may change.
Definition: resource.h:68
Definition: actor.h:30