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 // Extra space allocated for every resource. Originaly a safety area to make
31 // "precaching" of bytes in the gdi drawer easier. Now also taken into
32 // consideration when doing bounds checking in o5_stringOps().
33 #define SAFETY_AREA 2
34 
35 enum {
36  OF_OWNER_MASK = 0x0F,
37  OF_STATE_MASK = 0xF0,
38 
39  OF_STATE_SHL = 4
40 };
41 
43  uint32 _size;
44  uint32 _pos;
45  const byte *_ptr;
46  bool _smallHeader;
47 public:
48  ResourceIterator(const byte *searchin, bool smallHeader);
49  const byte *findNext(uint32 tag);
50 };
51 
52 enum : uint {
53  RES_INVALID_OFFSET = 0xFFFFFFFF
54 };
55 
56 class ScummEngine;
57 
74 };
75 
81  //friend class ScummDebugger;
82  //friend class ScummEngine;
83 protected:
84  ScummEngine *_vm;
85  Common::Mutex *_mutex;
86 
87 public:
88  class Resource {
89  public:
93  byte *_address;
94 
98  uint32 _size;
99 
100  protected:
110  byte _flags;
111 
116  byte _status;
117 
118  public:
122  byte _roomno;
123 
132  uint32 _roomoffs;
133 
134  public:
135  Resource();
136  ~Resource();
137 
138  void nuke();
139 
140  inline void setResourceCounter(byte counter);
141  inline byte getResourceCounter() const;
142 
143  void lock();
144  void unlock();
145  bool isLocked() const;
146 
147  // HE specific
148  void setModified();
149  bool isModified() const;
150  void setOffHeap();
151  void setOnHeap();
152  bool isOffHeap() const;
153  };
154 
158  class ResTypeData : public Common::Array<Resource> {
159  friend class ResourceManager;
160  public:
165 
171  uint32 _tag;
172 
173  public:
174  ResTypeData();
175  ~ResTypeData();
176  };
177  ResTypeData _types[rtLast + 1];
178 
179 protected:
180  uint32 _allocatedSize;
181  uint32 _maxHeapThreshold, _minHeapThreshold;
182  byte _expireCounter;
183 
184 public:
186  ~ResourceManager();
187 
188  void setHeapThreshold(int min, int max);
189  uint32 getHeapSize() { return _allocatedSize; }
190 
191  void allocResTypeData(ResType type, uint32 tag, int num, ResTypeMode mode);
192  void freeResources();
193 
194  byte *createResource(ResType type, ResId idx, uint32 size);
195  void nukeResource(ResType type, ResId idx);
196 
197 // inline Resource &getRes(ResType type, ResId idx) { return _types[type][idx]; }
198 // inline const Resource &getRes(ResType type, ResId idx) const { return _types[type][idx]; }
199 
200  bool isResourceLoaded(ResType type, ResId idx) const;
201 
202  void lock(ResType type, ResId idx);
203  void unlock(ResType type, ResId idx);
204  bool isLocked(ResType type, ResId idx) const;
205 
206  // HE Specific
207  void setModified(ResType type, ResId idx);
208  bool isModified(ResType type, ResId idx) const;
209  void setOffHeap(ResType type, ResId idx);
210  bool isOffHeap(ResType type, ResId idx) const;
211  void setOnHeap(ResType type, ResId idx);
212 
218  void increaseExpireCounter();
219 
223  void setResourceCounter(ResType type, ResId idx, byte counter);
224 
231  void increaseResourceCounters();
232 
233  void resourceStats();
234 
235 //protected:
236  bool validateResource(const char *str, ResType type, ResId idx) const;
237 protected:
238  void expireResources(uint32 size);
239 };
240 
241 } // End of namespace Scumm
242 
243 #endif
ResTypeMode _mode
Definition: resource.h:164
Resource comes from data files, does not change.
Definition: resource.h:72
uint32 _roomoffs
Definition: resource.h:132
Definition: array.h:52
Definition: resource.h:42
Definition: resource.h:80
ResType
Definition: scumm.h:243
Definition: scumm.h:508
byte _flags
Definition: resource.h:110
Definition: resource.h:88
uint32 _tag
Definition: resource.h:171
byte _status
Definition: resource.h:116
byte _roomno
Definition: resource.h:122
Definition: mutex.h:67
byte * _address
Definition: resource.h:93
uint32 _size
Definition: resource.h:98
ResTypeMode
Definition: resource.h:70
Definition: resource.h:158
Resource is generated during runtime and may change.
Definition: resource.h:71
Resource comes from data files, but may change.
Definition: resource.h:73
Definition: actor.h:30