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 NANCY_RESOURCE_RESOURCE_H
23#define NANCY_RESOURCE_RESOURCE_H
24
25#include "common/hash-str.h"
26#include "common/hashmap.h"
27#include "common/ptr.h"
28
29#include "engines/nancy/resource/cif.h"
30
31namespace Graphics {
32struct Surface;
33class ManagedSurface;
34}
35
36namespace Nancy {
37
38class IFF;
39
41public:
42 ResourceManager() = default;
43 ~ResourceManager() = default;
44
45 // Load an image resource. Can be either external .bmp file, or raw image data embedded inside a ciftree
46 // Ciftree images may have additional data dictating how they need to be blitted on screen (see ConversationCel).
47 // This is accessed via the outSrc/outDest parameters.
48 bool loadImage(const Common::Path &name, Graphics::ManagedSurface &surf, const Common::String &treeName = Common::String(), Common::Rect *outSrc = nullptr, Common::Rect *outDest = nullptr);
49
50 // Loads a picture through the image cache. Nancy19+ scripts make many records
51 // of the same pictures, and Nancy24 makes a new scene for every screen of
52 // the phone, so decoding a picture each time was slow. The cache keeps the
53 // pictures it loaded last decoded, and hands the same one to everyone who
54 // asks for it. Null when there is no such picture.
55 Common::SharedPtr<Graphics::ManagedSurface> loadCachedImage(const Common::String &name, const Common::String &treeName, Common::Rect *outDest = nullptr);
56
57 // Loads a single IFF file. These can either be inside standalone .cif files, or embedded inside a ciftree
58 IFF *loadIFF(const Common::Path &name);
59
60 // Loads a Lua script, which is what Nancy19 and up have in place of IFFs. These
61 // can be loose text files, standalone .cif files, or embedded inside a ciftree.
62 // The caller owns the stream.
63 Common::SeekableReadStream *loadScript(const Common::Path &name);
64
65 // Load a new ciftree
66 bool readCifTree(const Common::String &name, const Common::String &ext, int priority);
67
68 // Whether a ciftree of that name has been loaded. Nancy15 conversations use it
69 // to tell a cel archive apart from a movie of the same name (see ConversationCel).
70 bool hasCifTree(const Common::String &name) const;
71
72 // Change the search priority of an already loaded ciftree. Nancy15+ ships one
73 // copy of the popup UI resources per player character, so the tree belonging
74 // to the active character has to win name lookups against all the others.
75 void setCifTreePriority(const Common::String &name, int priority);
76 PatchTree *readPatchTree(Common::SeekableReadStream *stream, const Common::String &name, int priority);
77
78 // Debug functions
79
80 // Return a human-readable description of a single CIF file.
81 Common::String getCifDescription(const Common::String &treeName, const Common::Path &name) const;
82
83 // Return a list of all resources of a certain type (does not list external files)
84 void list(const Common::String &treeName, Common::Array<Common::Path> &outList, CifInfo::ResType type) const;
85
86 // Exports a single resource as a standalone .cif file
87 bool exportCif(const Common::Path &name);
88
89 // Exports a collection of resources as a ciftree
90 bool exportCifTree(const Common::String &treeName, const Common::Array<Common::Path> &names);
91
92private:
93 // An entry of the image cache. When the cache is full, the picture used
94 // longest ago makes room.
95 struct CachedImage {
97 Common::Rect dest;
98 uint32 lastUse = 0;
99 };
100
102
103 Common::Array<Common::String> _cifTreeNames;
104 ImageCache _imageCache; // by tree and name
105 uint32 _imageCacheUses = 0; // counts the lookups, for lastUse
106};
107
108} // End of namespace Nancy
109
110#endif // NANCY_RESOURCE_RESOURCE_H
Definition: path.h:52
Definition: stream.h:745
Definition: str.h:59
Definition: managed_surface.h:51
Definition: iff.h:35
Definition: cif.h:138
Definition: resource.h:40
Definition: formatinfo.h:28
Definition: actionmanager.h:32
Definition: rect.h:536