1 /* ResidualVM - A 3D game interpreter
2  *
3  * ResidualVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the AUTHORS
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef GRIM_RESOURCE_H
24 #define GRIM_RESOURCE_H
25 
26 #include "common/archive.h"
27 #include "common/array.h"
28 
29 #include "engines/grim/object.h"
30 
31 namespace Grim {
32 
33 class AnimationEmi;
34 class CMap;
35 class Costume;
36 class Font;
37 class KeyframeAnim;
38 class Material;
39 class Model;
40 class EMIModel;
41 class LipSync;
42 class TrackedObject;
43 class SaveGame;
44 class Skeleton;
45 class Sprite;
46 class EMICostume;
47 class Lab;
48 class Actor;
49 
50 typedef ObjectPtr<Material> MaterialPtr;
51 typedef ObjectPtr<Model> ModelPtr;
52 typedef ObjectPtr<CMap> CMapPtr;
53 typedef ObjectPtr<KeyframeAnim> KeyframeAnimPtr;
54 typedef ObjectPtr<Font> FontPtr;
55 typedef ObjectPtr<LipSync> LipSyncPtr;
56 typedef ObjectPtr<AnimationEmi> AnimationEmiPtr;
57 
58 class ResourceLoader {
59 public:
60 	ResourceLoader();
61 	~ResourceLoader();
62 
63 	CMap *loadColormap(const Common::String &fname);
64 	Costume *loadCostume(const Common::String &fname, Actor *owner, Costume *prevCost);
65 	Font *loadFont(const Common::String &fname);
66 	KeyframeAnim *loadKeyframe(const Common::String &fname);
67 	Material *loadMaterial(const Common::String &fname, CMap *c, bool clamp);
68 	Model *loadModel(const Common::String &fname, CMap *c, Model *parent = NULL);
69 	EMIModel *loadModelEMI(const Common::String &fname, EMICostume *costume);
70 	LipSync *loadLipSync(const Common::String &fname);
71 	Skeleton *loadSkeleton(const Common::String &fname);
72 	Sprite *loadSprite(const Common::String &fname, EMICostume *costume);
73 	AnimationEmi *loadAnimationEmi(const Common::String &filename);
74 	Common::SeekableReadStream *openNewStreamFile(Common::String fname, bool cache = false) const;
75 
76 	ModelPtr getModel(const Common::String &fname, CMap *c);
77 	CMapPtr getColormap(const Common::String &fname);
78 	KeyframeAnimPtr getKeyframe(const Common::String &fname);
79 	LipSyncPtr getLipSync(const Common::String &fname);
80 	AnimationEmiPtr getAnimationEmi(const Common::String &fname);
81 	void uncacheModel(Model *m);
82 	void uncacheColormap(CMap *c);
83 	void uncacheKeyframe(KeyframeAnim *kf);
84 	void uncacheLipSync(LipSync *l);
85 	void uncacheAnimationEmi(AnimationEmi *a);
86 
87 	struct ResourceCache {
88 		char *fname;
89 		byte *resPtr;
90 		uint32 len;
91 	};
92 
93 	static Common::String fixFilename(const Common::String &filename, bool append = true);
94 
95 private:
96 	Common::SeekableReadStream *loadFile(const Common::String &filename) const;
97 	Common::SeekableReadStream *getFileFromCache(const Common::String &filename) const;
98 	ResourceLoader::ResourceCache *getEntryFromCache(const Common::String &filename) const;
99 	void putIntoCache(const Common::String &fname, byte *res, uint32 len) const;
100 	void uncache(const char *fname) const;
101 
102 	mutable Common::Array<ResourceCache> _cache;
103 	mutable bool _cacheDirty;
104 	mutable int32 _cacheMemorySize;
105 
106 	Common::List<EMIModel *> _emiModels;
107 	Common::List<Model *> _models;
108 	Common::List<CMap *> _colormaps;
109 	Common::List<KeyframeAnim *> _keyframeAnims;
110 	Common::List<LipSync *> _lipsyncs;
111 	Common::List<AnimationEmi *> _emiAnims;
112 };
113 
114 extern ResourceLoader *g_resourceloader;
115 
116 } // end of namespace Grim
117 
118 #endif
119