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