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
22#ifndef DIRECTOR_UTIL_H
23#define DIRECTOR_UTIL_H
24
25namespace Common {
26class String;
27class FSNode;
28class Path;
29}
30
31namespace Director {
32
33int castNumToNum(const char *str);
34char *numToCastNum(int num);
35
36bool isAbsolutePath(const Common::String &path);
37
38Common::Path toSafePath(const Common::String &path);
39Common::String convertPath(const Common::String &path);
40
41Common::String unixToMacPath(const Common::String &path);
42
43Common::String getPath(const Common::String &path, const Common::String &cwd);
44
45Common::Path resolveFSPath(const Common::String &path, const Common::Path &base, bool directory);
46Common::Path resolvePathInner(const Common::String &path, const Common::Path &base, bool directory, const char *ext);
47Common::Path resolvePath(const Common::String &path, const Common::Path &base, bool directory, const char **exts);
48Common::Path resolvePartialPath(const Common::String &path, const Common::Path &base, bool directory, const char **exts);
49Common::Path resolvePathWithFuzz(const Common::String &path, const Common::Path &base, bool directory, const char **exts);
50Common::Path resolvePartialPathWithFuzz(const Common::String &path, const Common::Path &base, bool directory, const char **exts);
51Common::Path findAbsolutePath(const Common::String &path, bool directory = false, const char **exts = nullptr);
52Common::Path findPath(const Common::Path &path, bool currentFolder = true, bool searchPaths = true, bool directory = false, const char **exts = nullptr);
53Common::Path findPath(const Common::String &path, bool currentFolder = true, bool searchPaths = true, bool directory = false, const char **exts = nullptr, Common::String currentPath_ = "");
54Common::Path findMoviePath(const Common::String &path, bool currentFolder = true, bool searchPaths = true, Common::String currentPath = "");
55Common::Path findXLibPath(const Common::String &path, bool currentFolder = true, bool searchPaths = true);
56Common::Path findAudioPath(const Common::String &path, bool currentFolder = true, bool searchPaths = true);
57
58Common::String getFileNameFromModal(bool save, const Common::String &suggested, const Common::String &title, const char *ext = "txt");
59Common::String savePrefix();
60
61bool hasExtension(Common::String filename);
62
63Common::String getFileName(Common::String path);
64
65Common::String stripMacPath(const char *name);
66
67Common::String convertMacFilename(const char *name);
68
69Common::Path dumpScriptName(const char *prefix, int type, int id, const char *ext);
70Common::Path dumpFactoryName(const char *prefix, const char *name, const char *ext);
71
72bool isButtonSprite(SpriteType spriteType);
73
74uint32 macTimeSeed();
75
77public:
78 uint32 _seed;
79 uint32 _mask;
80 uint32 _len;
81
82 RandomState() {
83 _seed = _mask = _len = 0;
84 }
85
86 void setSeed(uint32 seed, bool runInit = true);
87 uint32 getSeed() { return _seed; }
88 int32 getRandom(int32 range);
89
90private:
91 void init(int len);
92 int32 genNextRandom();
93 int32 perlin(int32 val);
94};
95
96uint32 readVarInt(Common::SeekableReadStream &stream);
97
98Common::SeekableReadStreamEndian *readZlibData(Common::SeekableReadStream &stream, uint32 len, uint32 *outLen, bool bigEndian);
99
100uint16 humanVersion(uint16 ver);
101
102Common::Platform platformFromID(uint16 id);
103
104Common::CodePage getEncoding(Common::Platform platform, Common::Language language);
105Common::CodePage detectFontEncoding(Common::Platform platform, uint16 fontId);
106
107int charToNum(Common::u32char_type_t ch);
108Common::u32char_type_t numToChar(int num);
109int compareStringOrder(const Common::String &s1, const Common::String &s2);
110bool compareStringEquality(const Common::String &s1, const Common::String &s2);
111
112// Our implementation of strstr() with Director character order
113const char *d_strstr(const char *str, const char *substr);
114
115Common::String encodePathForDump(const Common::String &path);
116
117Common::String utf8ToPrintable(const Common::String &str);
118
119Common::String decodePlatformEncoding(Common::String input);
120
121Common::String formatStringForDump(const Common::String &str);
122
123inline byte lerpByte(byte a, byte b, int alpha, int span) {
124 int ai = static_cast<int>(a);
125 int bi = static_cast<int>(b);
126 span = CLIP<int>(span, 1, span);
127 alpha = CLIP<int>(alpha, 0, span);
128 return static_cast<byte>((bi * alpha + ai * (span - alpha)) / span);
129}
130
131inline void lerpPalette(byte *target, const byte *palA, int palALength, const byte *palB, int palBLength, int alpha, int span) {
132 for (int i = 0; i < 768; i++) {
133 target[i] = lerpByte(
134 i < palALength * 3 ? palA[i] : 0,
135 i < palBLength * 3 ? palB[i] : 0,
136 alpha,
137 span
138 );
139 }
140}
141
142} // End of namespace Director
143
144double readAppleFloat80(void *ptr);
145void hexdumpIfNotZero(byte *data, int len, const char *prefix);
146
147#endif
Definition: path.h:52
Definition: stream.h:944
Definition: stream.h:745
Definition: str.h:59
Definition: util.h:76
Language
Definition: language.h:45
Platform
Definition: platform.h:93
char32_t u32char_type_t
Definition: ustr.h:55
Definition: algorithm.h:29
Path
Definition: game.h:76