22 #ifndef GNAP_RESOURCE_H 23 #define GNAP_RESOURCE_H 25 #include "common/array.h" 26 #include "common/events.h" 27 #include "common/file.h" 28 #include "common/memstream.h" 29 #include "common/str.h" 30 #include "common/stream.h" 31 #include "common/substream.h" 32 #include "common/system.h" 34 #include "graphics/surface.h" 36 #include "gnap/datarchive.h" 57 int32 _additionalDelay;
59 int16 _maxTotalDuration;
62 SequenceAnimation() : frames(
nullptr), _additionalDelay(0), _framesCount(0), _maxTotalDuration(0) {}
80 int32 _animationsCount;
92 int16 _width, _height;
108 template <
class ResourceClass,
int ResourceType,
bool FreeAfterLoad>
118 ResourceClass *
get(
int resourceId) {
121 debug(9,
"Loading resource type %d with ID %08X from disk", ResourceType, resourceId);
122 resource =
new Resource(load(resourceId));
123 _cache[resourceId] = resource;
125 debug(9,
"Resource type %d with ID %08X was in cache", ResourceType, resourceId);
127 resource->_isLocked =
true;
128 return resource->_obj;
131 void release(
int resourceId) {
134 resource->_isLocked =
false;
137 void purge(
bool force =
false) {
138 for (CacheMapIterator it = _cache.begin(); it != _cache.end(); ++it) {
140 if (force || !resource->_isLocked) {
152 Resource(ResourceClass *obj) : _obj(obj), _isLocked(
false) {}
157 typedef typename CacheMap::iterator CacheMapIterator;
163 CacheMapIterator it = _cache.find(resourceId);
164 if (it != _cache.end())
169 ResourceClass *load(
int resourceId) {
170 if (_dat->getResourceType(resourceId) != ResourceType)
171 error(
"ResourceCache::load() Wrong resource type: Expected %d, got %d", ResourceType, _dat->getResourceType(resourceId));
173 byte *resourceData = _dat->loadResource(resourceId);
174 uint32 resourceSize = _dat->getResourceSize(resourceId);
175 ResourceClass *obj =
new ResourceClass(resourceData, resourceSize);
177 delete[] resourceData;
189 #endif // GNAP_RESOURCE_H Definition: resource.h:149
In find(In first, In last, const T &v)
Definition: algorithm.h:225
Definition: resource.h:56
Definition: resource.h:47
void debug(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Definition: datarchive.h:60
Definition: resource.h:84
Definition: resource.h:67
Definition: memstream.h:43
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Definition: character.h:25
Definition: resource.h:109
Definition: resource.h:99