ScummVM API documentation
resourcesystem.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 ILLUSIONS_RESOURCESYSTEM_H
23#define ILLUSIONS_RESOURCESYSTEM_H
24
25#include "common/array.h"
26#include "common/file.h"
27#include "common/hashmap.h"
28#include "common/memstream.h"
29#include "common/str.h"
30#include "common/substream.h"
31#include "common/system.h"
32
33namespace Illusions {
34
35#define ResourceTypeId(x) ((x) & 0xFFFF0000)
36
37class BaseResourceLoader;
38class BaseResourceReader;
39class IllusionsEngine;
40struct Resource;
41
43public:
44 virtual void load(Resource *resource);
45 virtual void unload();
46 virtual void pause();
47 virtual void unpause();
48 virtual ~ResourceInstance();
49};
50
51struct Resource {
52 bool _loaded;
53 uint32 _resId;
54 uint32 _sceneId;
55 uint32 _threadId;
56 byte *_data;
57 uint32 _dataSize;
58 int _gameId;
59 Common::String _filename;
60 ResourceInstance *_instance;
61 Resource() : _loaded(false), _resId(0), _sceneId(0), _threadId(0), _data(0), _dataSize(0), _instance(0) {
62 }
63 ~Resource() {
64 if (_instance)
65 _instance->unload();
66 delete _instance;
67 unloadData();
68 }
69 void loadData(BaseResourceReader *resReader);
70 void unloadData();
71};
72
73enum {
74 kRlfLoadFile,
75 kRlfFreeDataAfterLoad
76};
77
79public:
80 virtual ~BaseResourceLoader() {}
81 virtual void load(Resource *resource) = 0;
82 virtual bool isFlag(int flag) = 0;
83};
84
86public:
89
90 void addResourceLoader(uint32 resTypeId, BaseResourceLoader *resourceLoader);
91
92 void loadResource(uint32 resId, uint32 sceneId, uint32 threadId);
93 void unloadResourceById(uint32 resId);
94 void unloadResourcesBySceneId(uint32 sceneId);
95 void unloadSceneResources(uint32 sceneId1, uint32 sceneId2);
96 void unloadAllResources();
97 Resource *getResource(uint32 resId);
98
99protected:
101 typedef ResourceLoadersMap::iterator ResourceLoadersMapIterator;
102 IllusionsEngine *_vm;
103 ResourceLoadersMap _resourceLoaders;
104 BaseResourceLoader *getResourceLoader(uint32 resId);
105
107 typedef ResourcesArray::iterator ResourcesArrayIterator;
108 ResourcesArray _resources;
109
110 struct ResourceEqualById : public Common::UnaryFunction<const Resource*, bool> {
111 uint32 _resId;
112 ResourceEqualById(uint32 resId) : _resId(resId) {}
113 bool operator()(const Resource *resource) const {
114 return resource->_resId == _resId;
115 }
116 };
117
118 struct ResourceEqualByValue : public Common::UnaryFunction<const Resource*, bool> {
119 const Resource *_resource;
120 ResourceEqualByValue(const Resource *resource) : _resource(resource) {}
121 bool operator()(const Resource *resource) const {
122 return resource == _resource;
123 }
124 };
125
126 struct ResourceEqualBySceneId : public Common::UnaryFunction<const Resource*, bool> {
127 uint32 _sceneId;
128 ResourceEqualBySceneId(uint32 sceneId) : _sceneId(sceneId) {}
129 bool operator()(const Resource *resource) const {
130 return resource->_sceneId == _sceneId;
131 }
132 };
133
134 struct ResourceNotEqualByScenes : public Common::UnaryFunction<const Resource*, bool> {
135 uint32 _sceneId1, _sceneId2;
136 ResourceNotEqualByScenes(uint32 sceneId1, uint32 sceneId2) : _sceneId1(sceneId1), _sceneId2(sceneId2) {}
137 bool operator()(const Resource *resource) const {
138 return resource->_sceneId != _sceneId1 && resource->_sceneId != _sceneId2;
139 }
140 };
141
142 void unloadResource(Resource *resource);
143
144};
145
146} // End of namespace Illusions
147
148#endif // ILLUSIONS_RESOURCESYSTEM_H
Resource * * iterator
Definition: array.h:54
Definition: str.h:59
Definition: resourcesystem.h:78
Definition: resourcereader.h:29
Definition: illusions.h:92
Definition: resourcesystem.h:42
Definition: resourcesystem.h:85
Definition: func.h:43
Definition: resourcesystem.h:51
Definition: resourcesystem.h:110
Definition: resourcesystem.h:118