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