diff options
| author | Strangerke | 2013-06-26 23:11:34 +0200 |
|---|---|---|
| committer | Strangerke | 2013-06-26 23:11:34 +0200 |
| commit | 6e2d567bca53b6ffee771b4105e2e73dbd73f5b4 (patch) | |
| tree | 9880f0c496263ffb6928248d495ce4172dabed18 /common | |
| parent | ac387835e4527c1814919093b4e4bc9798d5742d (diff) | |
| parent | 6716fa39a6fb2a3925576288c256688c5aadd7e9 (diff) | |
| download | scummvm-rg350-6e2d567bca53b6ffee771b4105e2e73dbd73f5b4.tar.gz scummvm-rg350-6e2d567bca53b6ffee771b4105e2e73dbd73f5b4.tar.bz2 scummvm-rg350-6e2d567bca53b6ffee771b4105e2e73dbd73f5b4.zip | |
Merge branch 'master' of https://github.com/scummvm/scummvm into mortevielle
Conflicts:
engines/engines.mk
Diffstat (limited to 'common')
55 files changed, 381 insertions, 123 deletions
diff --git a/common/archive.cpp b/common/archive.cpp index 1323f14805..57ebeb2ca6 100644 --- a/common/archive.cpp +++ b/common/archive.cpp @@ -118,7 +118,7 @@ void SearchSet::addDirectory(const String &name, const FSNode &dir, int priority add(name, new FSDirectory(dir, depth, flat), priority); } -void SearchSet::addSubDirectoriesMatching(const FSNode &directory, String origPattern, bool ignoreCase, int priority) { +void SearchSet::addSubDirectoriesMatching(const FSNode &directory, String origPattern, bool ignoreCase, int priority, int depth, bool flat) { FSList subDirs; if (!directory.getChildren(subDirs)) return; @@ -161,9 +161,9 @@ void SearchSet::addSubDirectoriesMatching(const FSNode &directory, String origPa } if (nextPattern.empty()) - addDirectory(name, *i, priority); + addDirectory(name, *i, priority, depth, flat); else - addSubDirectoriesMatching(*i, nextPattern, ignoreCase, priority); + addSubDirectoriesMatching(*i, nextPattern, ignoreCase, priority, depth, flat); } } } diff --git a/common/archive.h b/common/archive.h index ffd86d786d..2f9736f032 100644 --- a/common/archive.h +++ b/common/archive.h @@ -184,8 +184,8 @@ public: * to assume that this method is using anything other than a simple case insensitive compare. * Thus do not use any tokens like '*' or '?' in the "caselessName" parameter of this function! */ - void addSubDirectoryMatching(const FSNode &directory, const String &caselessName, int priority = 0) { - addSubDirectoriesMatching(directory, caselessName, true, priority); + void addSubDirectoryMatching(const FSNode &directory, const String &caselessName, int priority = 0, int depth = 1, bool flat = false) { + addSubDirectoriesMatching(directory, caselessName, true, priority, depth, flat); } /** @@ -208,7 +208,7 @@ public: * * @see Common::matchString */ - void addSubDirectoriesMatching(const FSNode &directory, String origPattern, bool ignoreCase, int priority = 0); + void addSubDirectoriesMatching(const FSNode &directory, String origPattern, bool ignoreCase, int priority = 0, int depth = 1, bool flat = false); /** * Remove an archive from the searchable set. diff --git a/common/bufferedstream.h b/common/bufferedstream.h index 55ea8dc13b..6c859c98fe 100644 --- a/common/bufferedstream.h +++ b/common/bufferedstream.h @@ -61,6 +61,6 @@ SeekableReadStream *wrapBufferedSeekableReadStream(SeekableReadStream *parentStr */ WriteStream *wrapBufferedWriteStream(WriteStream *parentStream, uint32 bufSize); -} // End of namespace Common +} // End of namespace Common #endif diff --git a/common/c++11-compat.h b/common/c++11-compat.h new file mode 100644 index 0000000000..50d79bd79e --- /dev/null +++ b/common/c++11-compat.h @@ -0,0 +1,42 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + */ + +#ifndef COMMON_CPP11_COMPAT_H +#define COMMON_CPP11_COMPAT_H + +#if __cplusplus >= 201103L +#error "c++11-compat.h included when C++11 is available" +#endif + +// +// Custom nullptr replacement. This is not type safe as the real C++11 nullptr +// though. +// +#define nullptr 0 + +// +// Replacement for the override keyword. This allows compilation of code +// which uses it, but does not feature any semantic. +// +#define override + +#endif diff --git a/common/config-file.cpp b/common/config-file.cpp index 4224d7491d..0ce6dcf0c8 100644 --- a/common/config-file.cpp +++ b/common/config-file.cpp @@ -226,6 +226,15 @@ bool ConfigFile::saveToStream(WriteStream &stream) { return !stream.err(); } +void ConfigFile::addSection(const String §ion) { + Section *s = getSection(section); + if (s) + return; + + Section newSection; + newSection.name = section; + _sections.push_back(newSection); +} void ConfigFile::removeSection(const String §ion) { assert(isValidName(section)); @@ -380,4 +389,4 @@ void ConfigFile::Section::removeKey(const String &key) { } } -} // End of namespace Common +} // End of namespace Common diff --git a/common/config-file.h b/common/config-file.h index 7bc5604b4c..8bba851110 100644 --- a/common/config-file.h +++ b/common/config-file.h @@ -106,6 +106,7 @@ public: bool saveToStream(WriteStream &stream); bool hasSection(const String §ion) const; + void addSection(const String §ion); void removeSection(const String §ion); void renameSection(const String &oldName, const String &newName); @@ -134,6 +135,6 @@ private: */ -} // End of namespace Common +} // End of namespace Common #endif diff --git a/common/config-manager.h b/common/config-manager.h index 02d4ec3438..d43a7bec51 100644 --- a/common/config-manager.h +++ b/common/config-manager.h @@ -175,7 +175,7 @@ private: String _filename; }; -} // End of namespace Common +} // End of namespace Common /** Shortcut for accessing the configuration manager. */ #define ConfMan Common::ConfigManager::instance() diff --git a/common/cosinetables.cpp b/common/cosinetables.cpp index fe8f454e14..3b245750fa 100644 --- a/common/cosinetables.cpp +++ b/common/cosinetables.cpp @@ -34,10 +34,10 @@ CosineTable::CosineTable(int bitPrecision) { int m = 1 << _bitPrecision; double freq = 2 * M_PI / m; - _table = new float[m]; + _table = new float[m / 2]; - // Table contains cos(2*pi*x/n) for 0<=x<=n/4, - // followed by its reverse + // Table contains cos(2*pi*i/m) for 0<=i<m/4, + // followed by 3m/4<=i<m for (int i = 0; i <= m / 4; i++) _table[i] = cos(i * freq); diff --git a/common/cosinetables.h b/common/cosinetables.h index f9fb6fd59a..f5c95ec003 100644 --- a/common/cosinetables.h +++ b/common/cosinetables.h @@ -36,7 +36,14 @@ public: ~CosineTable(); /** - * Get pointer to table + * Get pointer to table. + * + * This table contains 2^bitPrecision/2 entries. + * The layout of this table is as follows: + * - Entries 0 up to (excluding) 2^bitPrecision/4: + * cos(0) till (excluding) cos(1/2*pi) + * - Entries 2^bitPrecision/4 up to (excluding) 2^bitPrecision/2: + * cos(3/2*pi) till (excluding) cos(2*pi) */ const float *getTable() { return _table; } diff --git a/common/debug-channels.h b/common/debug-channels.h index 54de9d491e..40d1ea667e 100644 --- a/common/debug-channels.h +++ b/common/debug-channels.h @@ -124,6 +124,6 @@ private: /** Shortcut for accessing the debug manager. */ #define DebugMan Common::DebugManager::instance() -} // End of namespace Common +} // End of namespace Common #endif diff --git a/common/debug.cpp b/common/debug.cpp index 9c3a93e5a6..ba5479c34d 100644 --- a/common/debug.cpp +++ b/common/debug.cpp @@ -102,7 +102,7 @@ bool DebugManager::isDebugChannelEnabled(uint32 channel) { return (gDebugChannelsEnabled & channel) != 0; } -} // End of namespace Common +} // End of namespace Common #ifndef DISABLE_TEXT_CONSOLE diff --git a/common/fft.h b/common/fft.h index bc58f1dded..ef5f6e95ad 100644 --- a/common/fft.h +++ b/common/fft.h @@ -67,7 +67,6 @@ private: Complex *_tmpBuf; int _splitRadix; - int _permutation; static int splitRadixPermutation(int i, int n, int inverse); diff --git a/common/file.cpp b/common/file.cpp index 12d73c9973..7ad6bc2e81 100644 --- a/common/file.cpp +++ b/common/file.cpp @@ -202,4 +202,4 @@ bool DumpFile::flush() { return _handle->flush(); } -} // End of namespace Common +} // End of namespace Common diff --git a/common/forbidden.h b/common/forbidden.h index eec80bba59..9050114442 100644 --- a/common/forbidden.h +++ b/common/forbidden.h @@ -333,11 +333,21 @@ #define isalpha(a) FORBIDDEN_SYMBOL_REPLACEMENT #endif + #ifndef FORBIDDEN_SYMBOL_EXCEPTION_iscntrl + #undef iscntrl + #define iscntrl(a) FORBIDDEN_SYMBOL_REPLACEMENT + #endif + #ifndef FORBIDDEN_SYMBOL_EXCEPTION_isdigit #undef isdigit #define isdigit(a) FORBIDDEN_SYMBOL_REPLACEMENT #endif + #ifndef FORBIDDEN_SYMBOL_EXCEPTION_isgraph + #undef isgraph + #define isgraph(a) FORBIDDEN_SYMBOL_REPLACEMENT + #endif + #ifndef FORBIDDEN_SYMBOL_EXCEPTION_isnumber #undef isnumber #define isnumber(a) FORBIDDEN_SYMBOL_REPLACEMENT @@ -348,6 +358,16 @@ #define islower(a) FORBIDDEN_SYMBOL_REPLACEMENT #endif + #ifndef FORBIDDEN_SYMBOL_EXCEPTION_isprint + #undef isprint + #define isprint(a) FORBIDDEN_SYMBOL_REPLACEMENT + #endif + + #ifndef FORBIDDEN_SYMBOL_EXCEPTION_ispunct + #undef ispunct + #define ispunct(a) FORBIDDEN_SYMBOL_REPLACEMENT + #endif + #ifndef FORBIDDEN_SYMBOL_EXCEPTION_isspace #undef isspace #define isspace(a) FORBIDDEN_SYMBOL_REPLACEMENT @@ -358,6 +378,11 @@ #define isupper(a) FORBIDDEN_SYMBOL_REPLACEMENT #endif + #ifndef FORBIDDEN_SYMBOL_EXCEPTION_isxdigit + #undef isxdigit + #define isxdigit(a) FORBIDDEN_SYMBOL_REPLACEMENT + #endif + #endif // FORBIDDEN_SYMBOL_EXCEPTION_ctype_h #ifndef FORBIDDEN_SYMBOL_EXCEPTION_mkdir diff --git a/common/fs.cpp b/common/fs.cpp index 0143c936d4..19a01074ea 100644 --- a/common/fs.cpp +++ b/common/fs.cpp @@ -335,4 +335,4 @@ int FSDirectory::listMembers(ArchiveMemberList &list) const { } -} // End of namespace Common +} // End of namespace Common diff --git a/common/func.h b/common/func.h index db57d73668..a4a80e5406 100644 --- a/common/func.h +++ b/common/func.h @@ -535,6 +535,6 @@ GENERATE_TRIVIAL_HASH_FUNCTOR(unsigned long); #undef GENERATE_TRIVIAL_HASH_FUNCTOR -} // End of namespace Common +} // End of namespace Common #endif diff --git a/common/hash-str.h b/common/hash-str.h index 08f0558bfd..190e6922eb 100644 --- a/common/hash-str.h +++ b/common/hash-str.h @@ -79,7 +79,7 @@ typedef HashMap<String, String, IgnoreCase_Hash, IgnoreCase_EqualTo> StringMap; -} // End of namespace Common +} // End of namespace Common #endif diff --git a/common/hashmap.cpp b/common/hashmap.cpp index ff8f9db9ce..e505d1dd25 100644 --- a/common/hashmap.cpp +++ b/common/hashmap.cpp @@ -106,4 +106,4 @@ void updateHashCollisionStats(int collisions, int dummyHits, int lookups, int ar } #endif -} // End of namespace Common +} // End of namespace Common diff --git a/common/hashmap.h b/common/hashmap.h index 7cf54997e8..42509d67e5 100644 --- a/common/hashmap.h +++ b/common/hashmap.h @@ -632,6 +632,6 @@ void HashMap<Key, Val, HashFunc, EqualFunc>::erase(const Key &key) { #undef HASHMAP_DUMMY_NODE -} // End of namespace Common +} // End of namespace Common #endif diff --git a/common/iff_container.cpp b/common/iff_container.cpp index 7bcbf86e0f..9c6e5f124a 100644 --- a/common/iff_container.cpp +++ b/common/iff_container.cpp @@ -22,6 +22,7 @@ #include "common/iff_container.h" #include "common/substream.h" +#include "common/util.h" namespace Common { @@ -75,4 +76,50 @@ void IFFParser::parse(IFFCallback &callback) { } while (!stop); } -} // End of namespace Common + +PackBitsReadStream::PackBitsReadStream(Common::ReadStream &input) : _input(&input) { +} + +PackBitsReadStream::~PackBitsReadStream() { +} + +bool PackBitsReadStream::eos() const { + return _input->eos(); +} + +uint32 PackBitsReadStream::read(void *dataPtr, uint32 dataSize) { + byte *out = (byte *)dataPtr; + uint32 left = dataSize; + + uint32 lenR = 0, lenW = 0; + while (left > 0 && !_input->eos()) { + lenR = _input->readByte(); + + if (lenR == 128) { + // no-op + lenW = 0; + } else if (lenR <= 127) { + // literal run + lenR++; + lenW = MIN(lenR, left); + for (uint32 j = 0; j < lenW; j++) { + *out++ = _input->readByte(); + } + for (; lenR > lenW; lenR--) { + _input->readByte(); + } + } else { // len > 128 + // expand run + lenW = MIN((256 - lenR) + 1, left); + byte val = _input->readByte(); + memset(out, val, lenW); + out += lenW; + } + + left -= lenW; + } + + return dataSize - left; +} + +} // End of namespace Common diff --git a/common/iff_container.h b/common/iff_container.h index 104ecf0f36..a730930b2c 100644 --- a/common/iff_container.h +++ b/common/iff_container.h @@ -77,22 +77,22 @@ page 376) */ #define ID_copy MKTAG('(','c',')',' ') /* EA IFF 85 Generic Copyright text chunk */ -/* ILBM chunks */ +/* IFF chunks */ #define ID_BMHD MKTAG('B','M','H','D') -/* ILBM BitmapHeader */ +/* IFF BitmapHeader */ #define ID_CMAP MKTAG('C','M','A','P') -/* ILBM 8bit RGB colormap */ +/* IFF 8bit RGB colormap */ #define ID_GRAB MKTAG('G','R','A','B') -/* ILBM "hotspot" coordiantes */ +/* IFF "hotspot" coordiantes */ #define ID_DEST MKTAG('D','E','S','T') -/* ILBM destination image info */ +/* IFF destination image info */ #define ID_SPRT MKTAG('S','P','R','T') -/* ILBM sprite identifier */ +/* IFF sprite identifier */ #define ID_CAMG MKTAG('C','A','M','G') /* Amiga viewportmodes */ #define ID_BODY MKTAG('B','O','D','Y') -/* ILBM image data */ +/* IFF image data */ #define ID_CRNG MKTAG('C','R','N','G') /* color cycling */ #define ID_CCRT MKTAG('C','C','R','T') @@ -114,7 +114,7 @@ page 376) */ #define ID_PCHG MKTAG('P','C','H','G') /* Line by line palette control information (Sebastiano Vigna) */ #define ID_PRVW MKTAG('P','R','V','W') -/* A mini duplicate ILBM used for preview (Gary Bonham) */ +/* A mini duplicate IFF used for preview (Gary Bonham) */ #define ID_XBMI MKTAG('X','B','M','I') /* eXtended BitMap Information (Soft-Logik) */ #define ID_CTBL MKTAG('C','T','B','L') @@ -239,6 +239,31 @@ public: }; +/** + * Decode a given PackBits encoded stream. + * + * PackBits is an RLE compression algorithm introduced by Apple. It is also + * used to encode ILBM and PBM subtypes of IFF files, and some flavors of + * TIFF. + * + * As there is no compression across row boundaries in the above formats, + * read() will extract a *new* line on each call, discarding any alignment + * or padding. + */ +class PackBitsReadStream : public Common::ReadStream { + +protected: + Common::ReadStream *_input; + +public: + PackBitsReadStream(Common::ReadStream &input); + ~PackBitsReadStream(); + + virtual bool eos() const; + + uint32 read(void *dataPtr, uint32 dataSize); +}; + } // namespace Common #endif diff --git a/common/language.h b/common/language.h index db552fc9c4..03b9ebaf8e 100644 --- a/common/language.h +++ b/common/language.h @@ -81,6 +81,6 @@ const String getGameGUIOptionsDescriptionLanguage(Common::Language lang); // TODO: Document this GUIO related function bool checkGameGUIOptionLanguage(Common::Language lang, const String &str); -} // End of namespace Common +} // End of namespace Common #endif diff --git a/common/macresman.cpp b/common/macresman.cpp index f2f020c6de..00562f746a 100644 --- a/common/macresman.cpp +++ b/common/macresman.cpp @@ -360,8 +360,8 @@ bool MacResManager::load(SeekableReadStream &stream) { _mapLength = stream.readUint32BE(); // do sanity check - if (_dataOffset >= (uint32)stream.size() || _mapOffset >= (uint32)stream.size() || - _dataLength + _mapLength > (uint32)stream.size()) { + if (stream.eos() || _dataOffset >= (uint32)stream.size() || _mapOffset >= (uint32)stream.size() || + _dataLength + _mapLength > (uint32)stream.size()) { _resForkOffset = -1; _mode = kResForkNone; return false; diff --git a/common/memorypool.h b/common/memorypool.h index 9a4e523d53..1cd725b99d 100644 --- a/common/memorypool.h +++ b/common/memorypool.h @@ -141,7 +141,7 @@ public: } }; -} // End of namespace Common +} // End of namespace Common /** * A custom placement new operator, using an arbitrary MemoryPool. diff --git a/common/memstream.h b/common/memstream.h index 497a178ab9..260fb64d84 100644 --- a/common/memstream.h +++ b/common/memstream.h @@ -173,6 +173,6 @@ public: bool seek(int32 offset, int whence = SEEK_SET); }; -} // End of namespace Common +} // End of namespace Common #endif diff --git a/common/mutex.cpp b/common/mutex.cpp index 4e6316528c..f912e79591 100644 --- a/common/mutex.cpp +++ b/common/mutex.cpp @@ -75,4 +75,4 @@ void StackLock::unlock() { g_system->unlockMutex(_mutex); } -} // End of namespace Common +} // End of namespace Common diff --git a/common/platform.cpp b/common/platform.cpp index 9986048b48..20ed970385 100644 --- a/common/platform.cpp +++ b/common/platform.cpp @@ -31,7 +31,7 @@ const PlatformDescription g_platforms[] = { { "amiga", "ami", "amiga", "Amiga", kPlatformAmiga }, { "atari", "atari-st", "st", "Atari ST", kPlatformAtariST }, { "c64", "c64", "c64", "Commodore 64", kPlatformC64 }, - { "pc", "dos", "ibm", "DOS", kPlatformPC }, + { "pc", "dos", "ibm", "DOS", kPlatformDOS }, { "pc98", "pc98", "pc98", "PC-98", kPlatformPC98 }, { "wii", "wii", "wii", "Nintendo Wii", kPlatformWii }, { "coco3", "coco3", "coco3", "CoCo3", kPlatformCoCo3 }, @@ -50,6 +50,8 @@ const PlatformDescription g_platforms[] = { { "playstation", "psx", "psx", "Sony PlayStation", kPlatformPSX }, { "cdi", "cdi", "cdi", "Philips CD-i", kPlatformCDi }, { "ios", "ios", "ios", "Apple iOS", kPlatformIOS }, + { "os2", "os2", "os2", "OS/2", kPlatformOS2 }, + { "beos", "beos", "beos", "BeOS", kPlatformBeOS }, { 0, 0, 0, "Default", kPlatformUnknown } }; diff --git a/common/platform.h b/common/platform.h index 1891c7096d..ac8772fa94 100644 --- a/common/platform.h +++ b/common/platform.h @@ -35,7 +35,7 @@ class String; * game in question. */ enum Platform { - kPlatformPC, + kPlatformDOS, kPlatformAmiga, kPlatformAtariST, kPlatformMacintosh, @@ -55,6 +55,8 @@ enum Platform { kPlatformPSX, kPlatformCDi, kPlatformIOS, + kPlatformOS2, + kPlatformBeOS, kPlatformUnknown = -1 }; @@ -75,6 +77,6 @@ extern const char *getPlatformCode(Platform id); extern const char *getPlatformAbbrev(Platform id); extern const char *getPlatformDescription(Platform id); -} // End of namespace Common +} // End of namespace Common #endif diff --git a/common/quicktime.cpp b/common/quicktime.cpp index 173d3c6a97..a3efc2b443 100644 --- a/common/quicktime.cpp +++ b/common/quicktime.cpp @@ -165,6 +165,8 @@ void QuickTimeParser::initParseTable() { { &QuickTimeParser::readWAVE, MKTAG('w', 'a', 'v', 'e') }, { &QuickTimeParser::readESDS, MKTAG('e', 's', 'd', 's') }, { &QuickTimeParser::readSMI, MKTAG('S', 'M', 'I', ' ') }, + { &QuickTimeParser::readDefault, MKTAG('g', 'm', 'h', 'd') }, + { &QuickTimeParser::readLeaf, MKTAG('g', 'm', 'i', 'n') }, { 0, 0 } }; @@ -442,7 +444,7 @@ int QuickTimeParser::readELST(Atom atom) { uint32 offset = 0; - for (uint32 i = 0; i < track->editCount; i++){ + for (uint32 i = 0; i < track->editCount; i++) { track->editList[i].trackDuration = _fd->readUint32BE(); track->editList[i].mediaTime = _fd->readSint32BE(); track->editList[i].mediaRate = Rational(_fd->readUint32BE(), 0x10000); @@ -477,6 +479,8 @@ int QuickTimeParser::readHDLR(Atom atom) { track->codecType = CODEC_TYPE_VIDEO; else if (type == MKTAG('s', 'o', 'u', 'n')) track->codecType = CODEC_TYPE_AUDIO; + else if (type == MKTAG('m', 'u', 's', 'i')) + track->codecType = CODEC_TYPE_MIDI; _fd->readUint32BE(); // component manufacture _fd->readUint32BE(); // component flags @@ -540,7 +544,7 @@ int QuickTimeParser::readSTSD(Atom atom) { _fd->readUint16BE(); // reserved _fd->readUint16BE(); // index - track->sampleDescs[i] = readSampleDesc(track, format); + track->sampleDescs[i] = readSampleDesc(track, format, size - 16); debug(0, "size=%d 4CC= %s codec_type=%d", size, tag2str(format), track->codecType); diff --git a/common/quicktime.h b/common/quicktime.h index 641718e13a..caa92578b1 100644 --- a/common/quicktime.h +++ b/common/quicktime.h @@ -120,7 +120,8 @@ protected: enum CodecType { CODEC_TYPE_MOV_OTHER, CODEC_TYPE_VIDEO, - CODEC_TYPE_AUDIO + CODEC_TYPE_AUDIO, + CODEC_TYPE_MIDI }; struct Track { @@ -161,7 +162,7 @@ protected: byte objectTypeMP4; }; - virtual SampleDesc *readSampleDesc(Track *track, uint32 format) = 0; + virtual SampleDesc *readSampleDesc(Track *track, uint32 format, uint32 descSize) = 0; uint32 _timeScale; uint32 _duration; diff --git a/common/random.cpp b/common/random.cpp index 55fa3cbd30..fd75534c44 100644 --- a/common/random.cpp +++ b/common/random.cpp @@ -59,4 +59,4 @@ uint RandomSource::getRandomNumberRng(uint min, uint max) { return getRandomNumber(max - min) + min; } -} // End of namespace Common +} // End of namespace Common diff --git a/common/random.h b/common/random.h index 90f2ed5cb0..c8aec58946 100644 --- a/common/random.h +++ b/common/random.h @@ -74,6 +74,6 @@ public: uint getRandomNumberRng(uint min, uint max); }; -} // End of namespace Common +} // End of namespace Common #endif diff --git a/common/rdft.h b/common/rdft.h index 3386940404..76e95c363a 100644 --- a/common/rdft.h +++ b/common/rdft.h @@ -20,7 +20,7 @@ * */ -// Based on eos' (I)RDFT code which is in turn +// Based on xoreos' (I)RDFT code which is in turn // Based upon the (I)RDFT code in FFmpeg // Copyright (c) 2009 Alex Converse <alex dot converse at gmail dot com> @@ -44,6 +44,40 @@ namespace Common { * * Used in engines: * - scumm + * + * + * It has four modes: + * + * Below, n = 1 << bits + * + * (I)DFT_R2C: + * input: + * n real floats + * output: + * n/2 complex floats (stored as real part followed by imag part). + * + * The output represents the first half of the (I)DFT of the input. + * If F is the complex (I)DFT of the input, then + * output[0] = F[0] + i * F[n/2] and + * output[k] = F[k] for k = 1 .. n/2-1. + * Note that F[0] and F[k] are real since the input is real, and + * the remaining values of F can be reconstructed from symmetry if desired. + * + * (I)DFT_C2R: + * input: + * n/2 complex floats + * output: + * n real floats + * + * The input encodes a complex vector x of length n that has the + * required symmetry to have a real (I)DFT: + * x[0] = Re(input[0]) + * x[k] = input[k] for k = 1 .. n/2-1 + * x[n/2] = Im(input[0]) + * x[k] = conj(input[n-k]) for k = n/2+1 .. n-1 + * The output is then the real (I)DFT of x, divided by 2. + * + * TODO: Is this division by 2 intentional? */ class RDFT { diff --git a/common/rect.h b/common/rect.h index 8d1243f7e4..5790cf7c0f 100644 --- a/common/rect.h +++ b/common/rect.h @@ -266,6 +266,6 @@ struct Rect { } }; -} // End of namespace Common +} // End of namespace Common #endif diff --git a/common/scummsys.h b/common/scummsys.h index 2f4efe702f..291de87dc9 100644 --- a/common/scummsys.h +++ b/common/scummsys.h @@ -51,7 +51,7 @@ #include <stdio.h> #include <stdarg.h> - // MSVC's vsnprintf is either non-existant (2003) or bugged since it + // MSVC's vsnprintf is either non-existent (2003) or bugged since it // does not always include a terminating NULL (2005+). To work around // that we fix up the _vsnprintf included. Note that the return value // will still not match C99's specs! @@ -144,7 +144,10 @@ #endif #endif - +// Include our C++11 compatability header for pre-C++11 compilers. +#if __cplusplus < 201103L +#include "common/c++11-compat.h" +#endif // Use config.h, generated by configure #if defined(HAVE_CONFIG_H) diff --git a/common/sinetables.cpp b/common/sinetables.cpp index a6ec99469d..7338166d39 100644 --- a/common/sinetables.cpp +++ b/common/sinetables.cpp @@ -34,15 +34,15 @@ SineTable::SineTable(int bitPrecision) { int m = 1 << _bitPrecision; double freq = 2 * M_PI / m; - _table = new float[m]; + _table = new float[m / 2]; - // Table contains sin(2*pi*x/n) for 0<=x<=n/4, - // followed by its reverse - for (int i = 0; i <= m / 4; i++) + // Table contains sin(2*pi*i/m) for 0<=i<m/4, + // followed by m/2<=i<3m/4 + for (int i = 0; i < m / 4; i++) _table[i] = sin(i * freq); - for (int i = 1; i < m / 4; i++) - _table[m / 2 - i] = _table[i]; + for (int i = 0; i < m / 4; i++) + _table[m / 4 + i] = -_table[i]; } SineTable::~SineTable() { diff --git a/common/sinetables.h b/common/sinetables.h index 16e203f26d..3489663661 100644 --- a/common/sinetables.h +++ b/common/sinetables.h @@ -37,6 +37,13 @@ public: /** * Get pointer to table + * + * This table contains 2^bitPrecision/2 entries. + * The layout of this table is as follows: + * - Entries 0 up to (excluding) 2^bitPrecision/4: + * sin(0) till (excluding) sin(1/2*pi) + * - Entries 2^bitPrecision/4 up to (excluding) 2^bitPrecision/2: + * sin(pi) till (excluding) sin(3/2*pi) */ const float *getTable() { return _table; } diff --git a/common/singleton.h b/common/singleton.h index d7078360f3..6e47f119ba 100644 --- a/common/singleton.h +++ b/common/singleton.h @@ -97,6 +97,6 @@ protected: #define DECLARE_SINGLETON(T) \ template<> T *Singleton<T>::_singleton = 0 -} // End of namespace Common +} // End of namespace Common #endif diff --git a/common/str.cpp b/common/str.cpp index 84805082ac..5d647ee4f0 100644 --- a/common/str.cpp +++ b/common/str.cpp @@ -370,7 +370,7 @@ void String::clear() { } void String::setChar(char c, uint32 p) { - assert(p <= _size); + assert(p < _size); makeUnique(); _str[p] = c; @@ -764,7 +764,7 @@ String tag2string(uint32 tag) { str[4] = '\0'; // Replace non-printable chars by dot for (int i = 0; i < 4; ++i) { - if (!isprint((unsigned char)str[i])) + if (!Common::isPrint(str[i])) str[i] = '.'; } return String(str); @@ -850,7 +850,7 @@ size_t strlcat(char *dst, const char *src, size_t size) { return dstLength + (src - srcStart); } -} // End of namespace Common +} // End of namespace Common // Portable implementation of stricmp / strcasecmp / strcmpi. // TODO: Rename this to Common::strcasecmp diff --git a/common/stream.cpp b/common/stream.cpp index 85647bfe3a..f49603c882 100644 --- a/common/stream.cpp +++ b/common/stream.cpp @@ -342,7 +342,7 @@ uint32 BufferedReadStream::read(void *dataPtr, uint32 dataSize) { return alreadyRead + dataSize; } -} // End of nameless namespace +} // End of anonymous namespace ReadStream *wrapBufferedReadStream(ReadStream *parentStream, uint32 bufSize, DisposeAfterUse::Flag disposeParentStream) { @@ -379,12 +379,25 @@ BufferedSeekableReadStream::BufferedSeekableReadStream(SeekableReadStream *paren bool BufferedSeekableReadStream::seek(int32 offset, int whence) { // If it is a "local" seek, we may get away with "seeking" around // in the buffer only. - // Note: We could try to handle SEEK_END and SEEK_SET, too, but - // since they are rarely used, it seems not worth the effort. _eos = false; // seeking always cancels EOS - if (whence == SEEK_CUR && (int)_pos + offset >= 0 && _pos + offset <= _bufSize) { - _pos += offset; + int relOffset = 0; + switch (whence) { + case SEEK_SET: + relOffset = offset - pos(); + break; + case SEEK_CUR: + relOffset = offset; + break; + case SEEK_END: + relOffset = (size() + offset) - pos(); + break; + default: + break; + } + + if ((int)_pos + relOffset >= 0 && _pos + relOffset <= _bufSize) { + _pos += relOffset; // Note: we do not need to reset parent's eos flag here. It is // sufficient that it is reset when actually seeking in the parent. @@ -393,14 +406,21 @@ bool BufferedSeekableReadStream::seek(int32 offset, int whence) { // just seek normally in the parent stream. if (whence == SEEK_CUR) offset -= (_bufSize - _pos); - _pos = _bufSize; + // We invalidate the buffer here. This assures that successive seeks + // do not have the chance to incorrectly think they seeked back into + // the buffer. + // Note: This does not take full advantage of the buffer. But it is + // a simple way to prevent nasty errors. It would be possible to take + // full advantage of the buffer by saving its actual start position. + // This seems not worth the effort for this seemingly uncommon use. + _pos = _bufSize = 0; _parentStream->seek(offset, whence); } return true; } -} // End of nameless namespace +} // End of anonymous namespace SeekableReadStream *wrapBufferedSeekableReadStream(SeekableReadStream *parentStream, uint32 bufSize, DisposeAfterUse::Flag disposeParentStream) { if (parentStream) @@ -482,7 +502,7 @@ public: }; -} // End of nameless namespace +} // End of anonymous namespace WriteStream *wrapBufferedWriteStream(WriteStream *parentStream, uint32 bufSize) { if (parentStream) @@ -490,4 +510,4 @@ WriteStream *wrapBufferedWriteStream(WriteStream *parentStream, uint32 bufSize) return 0; } -} // End of namespace Common +} // End of namespace Common diff --git a/common/stream.h b/common/stream.h index 26c04e5bf6..33ebc95a86 100644 --- a/common/stream.h +++ b/common/stream.h @@ -454,6 +454,6 @@ public: }; -} // End of namespace Common +} // End of namespace Common #endif diff --git a/common/taskbar.h b/common/taskbar.h index 6f28028e74..b4ec673739 100644 --- a/common/taskbar.h +++ b/common/taskbar.h @@ -136,7 +136,7 @@ public: virtual void clearError() {} }; -} // End of namespace Common +} // End of namespace Common #endif diff --git a/common/textconsole.cpp b/common/textconsole.cpp index ffa42e63a0..a721c121d5 100644 --- a/common/textconsole.cpp +++ b/common/textconsole.cpp @@ -40,7 +40,7 @@ void setErrorHandler(ErrorHandler handler) { } -} // End of namespace Common +} // End of namespace Common #ifndef DISABLE_TEXT_CONSOLE diff --git a/common/textconsole.h b/common/textconsole.h index 364c49b2e9..12f15e5e4b 100644 --- a/common/textconsole.h +++ b/common/textconsole.h @@ -56,7 +56,7 @@ typedef void (*ErrorHandler)(const char *msg); */ void setErrorHandler(ErrorHandler handler); -} // End of namespace Common +} // End of namespace Common void NORETURN_PRE error(const char *s, ...) GCC_PRINTF(1, 2) NORETURN_POST; diff --git a/common/unzip.cpp b/common/unzip.cpp index ab659343a2..69b9ff67cb 100644 --- a/common/unzip.cpp +++ b/common/unzip.cpp @@ -1534,4 +1534,4 @@ Archive *makeZipArchive(SeekableReadStream *stream) { return new ZipArchive(zipFile); } -} // End of namespace Common +} // End of namespace Common diff --git a/common/unzip.h b/common/unzip.h index 06480b0054..2e0dae831a 100644 --- a/common/unzip.h +++ b/common/unzip.h @@ -56,6 +56,6 @@ Archive *makeZipArchive(const FSNode &node); */ Archive *makeZipArchive(SeekableReadStream *stream); -} // End of namespace Common +} // End of namespace Common #endif diff --git a/common/updates.h b/common/updates.h index 4d58a216fb..0012808a17 100644 --- a/common/updates.h +++ b/common/updates.h @@ -95,7 +95,7 @@ public: virtual UpdateInterval getUpdateCheckInterval() { return kUpdateIntervalNotSupported; } }; -} // End of namespace Common +} // End of namespace Common #endif diff --git a/common/util.cpp b/common/util.cpp index 4d9ff11c5c..3d40fffff5 100644 --- a/common/util.cpp +++ b/common/util.cpp @@ -26,6 +26,7 @@ #define FORBIDDEN_SYMBOL_EXCEPTION_islower #define FORBIDDEN_SYMBOL_EXCEPTION_isspace #define FORBIDDEN_SYMBOL_EXCEPTION_isupper +#define FORBIDDEN_SYMBOL_EXCEPTION_isprint #include "common/util.h" @@ -144,4 +145,8 @@ bool isUpper(int c) { return isupper((byte)c); } +bool isPrint(int c) { + ENSURE_ASCII_CHAR(c); + return isprint((byte)c); +} } // End of namespace Common diff --git a/common/util.h b/common/util.h index 78340980d5..4ca1c42929 100644 --- a/common/util.h +++ b/common/util.h @@ -165,6 +165,17 @@ bool isSpace(int c); */ bool isUpper(int c); -} // End of namespace Common +/** + * Test whether the given character is printable. This includes the space + * character (' '). + * + * If the parameter is outside the range of a signed or unsigned char, then + * false is returned. + * + * @param c the character to test + * @return true if the character is printable, false otherwise. + */ +bool isPrint(int c); +} // End of namespace Common #endif diff --git a/common/winexe.cpp b/common/winexe.cpp index 7cfc140452..877ab6baa1 100644 --- a/common/winexe.cpp +++ b/common/winexe.cpp @@ -73,7 +73,7 @@ String WinResourceID::toString() const { if (_idType == kIDTypeString) return _name; else if (_idType == kIDTypeNumerical) - return String::format("%08x", _id); + return String::format("0x%08x", _id); return ""; } diff --git a/common/winexe_ne.cpp b/common/winexe_ne.cpp index 8690f6795b..6bb40e0980 100644 --- a/common/winexe_ne.cpp +++ b/common/winexe_ne.cpp @@ -187,8 +187,8 @@ uint32 NEResources::getResourceTableOffset() { static const char *s_resTypeNames[] = { "", "cursor", "bitmap", "icon", "menu", "dialog", "string", "font_dir", "font", "accelerator", "rc_data", "msg_table", - "group_cursor", "group_icon", "version", "dlg_include", - "plug_play", "vxd", "ani_cursor", "ani_icon", "html", + "group_cursor", "group_icon", "", "", "version", "dlg_include", + "", "plug_play", "vxd", "ani_cursor", "ani_icon", "html", "manifest" }; @@ -200,9 +200,16 @@ bool NEResources::readResourceTable(uint32 offset) { return false; uint32 align = 1 << _exe->readUint16LE(); - uint16 typeID = _exe->readUint16LE(); + while (typeID != 0) { + // High bit of the type means integer type + WinResourceID type; + if (typeID & 0x8000) + type = typeID & 0x7FFF; + else + type = getResourceString(*_exe, offset + typeID); + uint16 resCount = _exe->readUint16LE(); _exe->skip(4); // reserved @@ -218,17 +225,18 @@ bool NEResources::readResourceTable(uint32 offset) { res.handle = _exe->readUint16LE(); res.usage = _exe->readUint16LE(); - res.type = typeID; + res.type = type; - if ((id & 0x8000) == 0) - res.id = getResourceString(*_exe, offset + id); - else + // High bit means integer type + if (id & 0x8000) res.id = id & 0x7FFF; + else + res.id = getResourceString(*_exe, offset + id); - if (typeID & 0x8000 && ((typeID & 0x7FFF) < ARRAYSIZE(s_resTypeNames))) + if (typeID & 0x8000 && ((typeID & 0x7FFF) < ARRAYSIZE(s_resTypeNames)) && s_resTypeNames[typeID & 0x7FFF][0] != 0) debug(2, "Found resource %s %s", s_resTypeNames[typeID & 0x7FFF], res.id.toString().c_str()); else - debug(2, "Found resource %04x %s", typeID, res.id.toString().c_str()); + debug(2, "Found resource %s %s", type.toString().c_str(), res.id.toString().c_str()); _resources.push_back(res); } @@ -257,7 +265,7 @@ String NEResources::getResourceString(SeekableReadStream &exe, uint32 offset) { return string; } -const NEResources::Resource *NEResources::findResource(uint16 type, WinResourceID id) const { +const NEResources::Resource *NEResources::findResource(const WinResourceID &type, const WinResourceID &id) const { for (List<Resource>::const_iterator it = _resources.begin(); it != _resources.end(); ++it) if (it->type == type && it->id == id) return &*it; @@ -265,7 +273,7 @@ const NEResources::Resource *NEResources::findResource(uint16 type, WinResourceI return 0; } -SeekableReadStream *NEResources::getResource(uint16 type, WinResourceID id) { +SeekableReadStream *NEResources::getResource(const WinResourceID &type, const WinResourceID &id) { const Resource *res = findResource(type, id); if (!res) @@ -275,7 +283,7 @@ SeekableReadStream *NEResources::getResource(uint16 type, WinResourceID id) { return _exe->readStream(res->size); } -const Array<WinResourceID> NEResources::getIDList(uint16 type) const { +const Array<WinResourceID> NEResources::getIDList(const WinResourceID &type) const { Array<WinResourceID> idArray; for (List<Resource>::const_iterator it = _resources.begin(); it != _resources.end(); ++it) diff --git a/common/winexe_ne.h b/common/winexe_ne.h index 4a1b2343df..f00941412f 100644 --- a/common/winexe_ne.h +++ b/common/winexe_ne.h @@ -34,27 +34,27 @@ class SeekableReadStream; /** The default Windows resources. */ enum NEResourceType { - kNECursor = 0x8001, - kNEBitmap = 0x8002, - kNEIcon = 0x8003, - kNEMenu = 0x8004, - kNEDialog = 0x8005, - kNEString = 0x8006, - kNEFontDir = 0x8007, - kNEFont = 0x8008, - kNEAccelerator = 0x8009, - kNERCData = 0x800A, - kNEMessageTable = 0x800B, - kNEGroupCursor = 0x800C, - kNEGroupIcon = 0x800D, - kNEVersion = 0x8010, - kNEDlgInclude = 0x8011, - kNEPlugPlay = 0x8013, - kNEVXD = 0x8014, - kNEAniCursor = 0x8015, - kNEAniIcon = 0x8016, - kNEHTML = 0x8017, - kNEManifest = 0x8018 + kNECursor = 0x01, + kNEBitmap = 0x02, + kNEIcon = 0x03, + kNEMenu = 0x04, + kNEDialog = 0x05, + kNEString = 0x06, + kNEFontDir = 0x07, + kNEFont = 0x08, + kNEAccelerator = 0x09, + kNERCData = 0x0A, + kNEMessageTable = 0x0B, + kNEGroupCursor = 0x0C, + kNEGroupIcon = 0x0D, + kNEVersion = 0x10, + kNEDlgInclude = 0x11, + kNEPlugPlay = 0x13, + kNEVXD = 0x14, + kNEAniCursor = 0x15, + kNEAniIcon = 0x16, + kNEHTML = 0x17, + kNEManifest = 0x18 }; /** @@ -81,17 +81,17 @@ public: bool loadFromEXE(SeekableReadStream *stream); /** Return a list of resources for a given type. */ - const Array<WinResourceID> getIDList(uint16 type) const; + const Array<WinResourceID> getIDList(const WinResourceID &type) const; /** Return a stream to the specified resource (or 0 if non-existent). */ - SeekableReadStream *getResource(uint16 type, WinResourceID id); + SeekableReadStream *getResource(const WinResourceID &type, const WinResourceID &id); private: /** A resource. */ struct Resource { WinResourceID id; - uint16 type; ///< Type of the resource. + WinResourceID type; ///< Type of the resource. uint32 offset; ///< Offset within the EXE. uint32 size; ///< Size of the data. @@ -112,7 +112,7 @@ private: bool readResourceTable(uint32 offset); /** Find a specific resource. */ - const Resource *findResource(uint16 type, WinResourceID id) const; + const Resource *findResource(const WinResourceID &type, const WinResourceID &id) const; /** Read a resource string. */ static String getResourceString(SeekableReadStream &exe, uint32 offset); diff --git a/common/xmlparser.cpp b/common/xmlparser.cpp index f0b7f1cc81..c80d5e15be 100644 --- a/common/xmlparser.cpp +++ b/common/xmlparser.cpp @@ -298,7 +298,7 @@ bool XMLParser::closeKey() { bool XMLParser::parse() { if (_stream == 0) - return parserError("XML stream not ready for reading."); + return false; // Make sure we are at the start of the stream. _stream->seek(0, SEEK_SET); diff --git a/common/zlib.cpp b/common/zlib.cpp index fc8f351054..920338e57e 100644 --- a/common/zlib.cpp +++ b/common/zlib.cpp @@ -392,17 +392,21 @@ public: #endif // USE_ZLIB SeekableReadStream *wrapCompressedReadStream(SeekableReadStream *toBeWrapped, uint32 knownSize) { -#if defined(USE_ZLIB) if (toBeWrapped) { uint16 header = toBeWrapped->readUint16BE(); bool isCompressed = (header == 0x1F8B || ((header & 0x0F00) == 0x0800 && header % 31 == 0)); toBeWrapped->seek(-2, SEEK_CUR); - if (isCompressed) + if (isCompressed) { +#if defined(USE_ZLIB) return new GZipReadStream(toBeWrapped, knownSize); - } +#else + delete toBeWrapped; + return NULL; #endif + } + } return toBeWrapped; } @@ -415,4 +419,4 @@ WriteStream *wrapCompressedWriteStream(WriteStream *toBeWrapped) { } -} // End of namespace Common +} // End of namespace Common diff --git a/common/zlib.h b/common/zlib.h index 6a840f5fdc..d940f3f3a1 100644 --- a/common/zlib.h +++ b/common/zlib.h @@ -103,7 +103,9 @@ bool inflateZlibInstallShield(byte *dst, uint dstLen, const byte *src, uint srcL * provides transparent on-the-fly decompression. Assumes the data it * retrieves from the wrapped stream to be either uncompressed or in gzip * format. In the former case, the original stream is returned unmodified - * (and in particular, not wrapped). + * (and in particular, not wrapped). In the latter case the stream is + * returned wrapped, unless there is no ZLIB support, then NULL is returned + * and the old stream is destroyed. * * Certain GZip-formats don't supply an easily readable length, if you * still need the length carried along with the stream, and you know @@ -129,6 +131,6 @@ SeekableReadStream *wrapCompressedReadStream(SeekableReadStream *toBeWrapped, ui */ WriteStream *wrapCompressedWriteStream(WriteStream *toBeWrapped); -} // End of namespace Common +} // End of namespace Common #endif |
