ScummVM API documentation
util.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 #ifndef NANCY_UTIL_H
22 #define NANCY_UTIL_H
23 
24 #include "common/array.h"
25 #include "common/hashmap.h"
26 #include "common/path.h"
27 #include "common/rect.h"
28 #include "common/serializer.h"
29 
30 #include "engines/nancy/commontypes.h"
31 
32 namespace Nancy {
33 
34 struct CapturedPicture;
35 
36 void readRect(Common::SeekableReadStream &stream, Common::Rect &inRect);
37 void readRect(Common::Serializer &stream, Common::Rect &inRect, Common::Serializer::Version minVersion = 0, Common::Serializer::Version maxVersion = Common::Serializer::kLastVersion);
38 void readRectArray(Common::SeekableReadStream &stream, Common::Array<Common::Rect> &inArray, uint num, uint totalNum = 0);
39 void readRectArray(Common::Serializer &stream, Common::Array<Common::Rect> &inArray, uint num, uint totalNum = 0, Common::Serializer::Version minVersion = 0, Common::Serializer::Version maxVersion = Common::Serializer::kLastVersion);
40 
41 void readRect16(Common::SeekableReadStream &stream, Common::Rect &inRect);
42 void readRect16(Common::Serializer &stream, Common::Rect &inRect, Common::Serializer::Version minVersion = 0, Common::Serializer::Version maxVersion = Common::Serializer::kLastVersion);
43 void readRectArray16(Common::SeekableReadStream &stream, Common::Array<Common::Rect> &inArray, uint num, uint totalNum = 0);
44 void readRectArray16(Common::Serializer &stream, Common::Array<Common::Rect> &inArray, uint num, uint totalNum = 0, Common::Serializer::Version minVersion = 0, Common::Serializer::Version maxVersion = Common::Serializer::kLastVersion);
45 
46 void readFilename(Common::SeekableReadStream &stream, Common::String &inString);
47 void readFilename(Common::Serializer &stream, Common::String &inString, Common::Serializer::Version minVersion = 0, Common::Serializer::Version maxVersion = Common::Serializer::kLastVersion);
48 inline void readFilename(Common::SeekableReadStream &stream, Common::Path &inPath) {
49  Common::String inString;
50  readFilename(stream, inString);
51  inPath = Common::Path(inString);
52 }
53 inline void readFilename(Common::Serializer &stream, Common::Path &inPath, Common::Serializer::Version minVersion = 0, Common::Serializer::Version maxVersion = Common::Serializer::kLastVersion) {
54  Common::String inString;
55  readFilename(stream, inString, minVersion, maxVersion);
56  inPath = Common::Path(inString);
57 }
58 void readFilenameArray(Common::SeekableReadStream &stream, Common::Array<Common::String> &inArray, uint num);
59 void readFilenameArray(Common::Serializer &stream, Common::Array<Common::String> &inArray, uint num, Common::Serializer::Version minVersion = 0, Common::Serializer::Version maxVersion = Common::Serializer::kLastVersion);
60 void readFilenameArray(Common::SeekableReadStream &stream, Common::Array<Common::Path> &inArray, uint num);
61 void readFilenameArray(Common::Serializer &stream, Common::Array<Common::Path> &inArray, uint num, Common::Serializer::Version minVersion = 0, Common::Serializer::Version maxVersion = Common::Serializer::kLastVersion);
62 
63 void assembleTextLine(char *rawCaption, Common::String &output, uint size);
64 
65 // Resolves a subtitle/caption string that may be a key into an engine-data CVTX text
66 // table (AUTOTEXT by default, CONVO for some puzzles). Returns the table's entry for
67 // `keyOrText` when the table exists and contains that key, otherwise returns `fallback`.
68 Common::String resolveSubtitleText(const Common::String &keyOrText, const Common::String &fallback = Common::String(), const char *tableID = "AUTOTEXT");
69 
70 // Reads a 30-byte, NUL-terminated subtitle string from `stream` and resolves it as an
71 // AUTOTEXT key, falling back to the literal text when the key is not present in the table.
72 Common::String readSubtitleText(Common::SeekableReadStream &stream);
73 
74 // One of the 23-byte hotspot records the Nancy 13 and 14 puzzle records end with.
75 struct ExitHotspot {
76  Common::Rect hotspot;
77  uint16 cursorType = 0;
79  FlagDescription flag;
80 };
81 
82 // Reads the count-prefixed array of those records. Most puzzles describe a single
83 // give-up hotspot, but a record may carry several. The field after the scene id is
84 // an event-flag label, NOT a frame id, so an exit always lands on the first frame.
85 // Leaves continueSceneSound alone, as the puzzles differ on it.
86 void readExitHotspots(Common::SeekableReadStream &stream, Common::Array<ExitHotspot> &hotspots);
87 
88 // Reads the same array but keeps only the first record.
89 void readExitHotspot(Common::SeekableReadStream &stream, Common::Rect &hotspot, uint16 &cursorType,
91 
92 // Shows `text` as a single line in the game textbox, replacing its current contents.
93 // Does nothing when `text` is empty or when the player has subtitles disabled. A
94 // non-negative `overrideFontID` selects a font other than the textbox default. When
95 // `forceRedraw` is true, the textbox is redrawn immediately instead of on the next
96 // render pass.
97 void showSubtitle(const Common::String &text, bool forceRedraw = false, int overrideFontID = -1);
98 
99 // Maps a screen-space rect onto the live viewport's (scrolled) background, clipped
100 // to it. An empty rect means the whole visible viewport.
101 Common::Rect viewportScreenToBackground(const Common::Rect &screenRegion);
102 
103 // Grabs a background-space region of the live viewport into `picture`, converted to
104 // BGRA32 so it can be redisplayed and saved. Used by both cameras.
105 bool captureViewportPicture(const Common::Rect &backgroundRegion, CapturedPicture &picture);
106 
107 void readUIButton(Common::SeekableReadStream &stream, UIButtonRecord &dst);
108 void readUISlider(Common::SeekableReadStream &stream, UISliderRecord &dst);
109 void readUIPopupHeader(Common::SeekableReadStream &stream, UIPopupHeader &dst);
110 void readUIButtonSlot(Common::SeekableReadStream &stream, UIButtonSlot &dst);
111 
112 // Abstract base class used for loading data that would take too much time in a single frame
114 public:
115  DeferredLoader() {}
116  virtual ~DeferredLoader() {}
117 
118  // Calls loadInner() one or many times, until its allotted time is done
119  bool load(uint32 endTime);
120 
121 protected:
122  // Contains the actual loading logic, split up into tasks that are as small as possible
123  virtual bool loadInner() = 0;
124 };
125 
126 } // End of namespace Nancy
127 
128 #endif // NANCY_UTIL_H
Definition: str.h:59
Definition: commontypes.h:179
Definition: util.h:75
Definition: rect.h:536
Definition: path.h:52
Definition: commontypes.h:441
Definition: stream.h:745
Definition: serializer.h:80
Definition: util.h:113
Definition: commontypes.h:414
Definition: commontypes.h:461
Definition: commontypes.h:433
Definition: commontypes.h:194
Definition: puzzledata.h:282
Definition: actionmanager.h:32