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, Common::String currentPath_ = "");
54 Common::Path findMoviePath(const Common::String &path, bool currentFolder = true, bool searchPaths = true, Common::String currentPath = "");
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 uint32 macTimeSeed();
75 
76 class RandomState {
77 public:
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 
90 private:
91  void init(int len);
92  int32 genNextRandom();
93  int32 perlin(int32 val);
94 };
95 
96 uint32 readVarInt(Common::SeekableReadStream &stream);
97 
98 Common::SeekableReadStreamEndian *readZlibData(Common::SeekableReadStream &stream, uint32 len, uint32 *outLen, bool bigEndian);
99 
100 uint16 humanVersion(uint16 ver);
101 
102 Common::Platform platformFromID(uint16 id);
103 
104 Common::CodePage getEncoding(Common::Platform platform, Common::Language language);
105 Common::CodePage detectFontEncoding(Common::Platform platform, uint16 fontId);
106 
107 int charToNum(Common::u32char_type_t ch);
108 Common::u32char_type_t numToChar(int num);
109 int compareStringOrder(const Common::String &s1, const Common::String &s2);
110 bool compareStringEquality(const Common::String &s1, const Common::String &s2);
111 
112 // Our implementation of strstr() with Director character order
113 const char *d_strstr(const char *str, const char *substr);
114 
115 Common::String encodePathForDump(const Common::String &path);
116 
117 Common::String utf8ToPrintable(const Common::String &str);
118 
119 Common::String decodePlatformEncoding(Common::String input);
120 
121 Common::String formatStringForDump(const Common::String &str);
122 
123 inline 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 
131 inline 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 
144 double readAppleFloat80(void *ptr);
145 void hexdumpIfNotZero(byte *data, int len, const char *prefix);
146 
147 #endif
Definition: str.h:59
Definition: util.h:76
Definition: path.h:52
Definition: stream.h:745
Definition: archive.h:36
Path
Definition: game.h:76
Definition: algorithm.h:29
char32_t u32char_type_t
Definition: ustr.h:41
Definition: stream.h:944
Platform
Definition: platform.h:93
Language
Definition: language.h:45