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