diff options
author | David Corrales | 2007-05-26 20:23:24 +0000 |
---|---|---|
committer | David Corrales | 2007-05-26 20:23:24 +0000 |
commit | 3646c968c9578c2a94d65ebd5fb06ec835f8c51d (patch) | |
tree | 8b57b339ebb31a1d7a67f1678aa5dc5c7759070a /common | |
parent | d1f56d93f934150f4b579c2e90564e2bf035f113 (diff) | |
parent | ac45c5b33d834acbc9718f89be76e49d403a4d2c (diff) | |
download | scummvm-rg350-3646c968c9578c2a94d65ebd5fb06ec835f8c51d.tar.gz scummvm-rg350-3646c968c9578c2a94d65ebd5fb06ec835f8c51d.tar.bz2 scummvm-rg350-3646c968c9578c2a94d65ebd5fb06ec835f8c51d.zip |
Merged the fs branch with trunk. r26472:26948
svn-id: r26949
Diffstat (limited to 'common')
-rw-r--r-- | common/advancedDetector.cpp | 79 | ||||
-rw-r--r-- | common/algorithm.h | 103 | ||||
-rw-r--r-- | common/array.h | 34 | ||||
-rw-r--r-- | common/config-manager.cpp | 2 | ||||
-rw-r--r-- | common/endian.h | 4 | ||||
-rw-r--r-- | common/func.h | 240 | ||||
-rw-r--r-- | common/hash-str.h | 2 | ||||
-rw-r--r-- | common/iff_container.h | 228 | ||||
-rw-r--r-- | common/list.h | 6 | ||||
-rw-r--r-- | common/rect.h | 6 | ||||
-rw-r--r-- | common/scummsys.h | 28 | ||||
-rw-r--r-- | common/singleton.h | 13 | ||||
-rw-r--r-- | common/str.cpp | 5 | ||||
-rw-r--r-- | common/str.h | 4 | ||||
-rw-r--r-- | common/system.h | 8 | ||||
-rw-r--r-- | common/util.cpp | 23 | ||||
-rw-r--r-- | common/util.h | 21 |
17 files changed, 651 insertions, 155 deletions
diff --git a/common/advancedDetector.cpp b/common/advancedDetector.cpp index 792acf47b2..84b8365584 100644 --- a/common/advancedDetector.cpp +++ b/common/advancedDetector.cpp @@ -254,7 +254,9 @@ static ADGameDescList detectGame(const FSList *fslist, const Common::ADParams &p IntMap filesSize; IntMap allFiles; - String tstr, tstr2; + File testFile; + + String tstr; uint i; char md5str[32+1]; @@ -273,49 +275,47 @@ static ADGameDescList detectGame(const FSList *fslist, const Common::ADParams &p for (fileDesc = g->filesDescriptions; fileDesc->fileName; fileDesc++) { tstr = String(fileDesc->fileName); tstr.toLowercase(); - tstr2 = tstr + "."; filesList[tstr] = true; - filesList[tstr2] = true; } } - + if (fslist != 0) { + // Get the information of the existing files for (FSList::const_iterator file = fslist->begin(); file != fslist->end(); ++file) { - Common::File f; - if (file->isDirectory()) continue; tstr = file->name(); tstr.toLowercase(); - tstr2 = tstr + "."; - allFiles[tstr] = allFiles[tstr2] = 1; + // Strip any trailing dot + if (tstr.lastChar() == '.') + tstr.deleteLastChar(); + + allFiles[tstr] = true; debug(3, "+ %s", tstr.c_str()); - if (!filesList.contains(tstr) && !filesList.contains(tstr2)) continue; + if (!filesList.contains(tstr)) continue; if (!md5_file_string(*file, md5str, params.md5Bytes)) continue; - filesMD5[tstr] = filesMD5[tstr2] = md5str; + filesMD5[tstr] = md5str; debug(3, "> %s: %s", tstr.c_str(), md5str); - if (f.open(file->path())) { - filesSize[tstr] = filesSize[tstr2] = (int32)f.size(); - f.close(); + if (testFile.open(file->path())) { + filesSize[tstr] = (int32)testFile.size(); + testFile.close(); } } } else { - File testFile; - + // Get the information of the requested files for (StringSet::const_iterator file = filesList.begin(); file != filesList.end(); ++file) { tstr = file->_key; - tstr.toLowercase(); debug(3, "+ %s", tstr.c_str()); if (!filesMD5.contains(tstr)) { - if (testFile.open(file->_key)) { - filesSize[tstr] = filesSize[tstr2] = (int32)testFile.size(); + if (testFile.open(tstr) || testFile.open(tstr + ".")) { + filesSize[tstr] = (int32)testFile.size(); testFile.close(); if (md5_file_string(file->_key.c_str(), md5str, params.md5Bytes)) { @@ -330,6 +330,7 @@ static ADGameDescList detectGame(const FSList *fslist, const Common::ADParams &p ADGameDescList matched; int maxFilesMatched = 0; + // MD5 based matching for (i = 0, descPtr = params.descs; ((const ADGameDescription *)descPtr)->gameid != 0; descPtr += params.descItemSize, ++i) { g = (const ADGameDescription *)descPtr; fileMissing = false; @@ -341,18 +342,17 @@ static ADGameDescList detectGame(const FSList *fslist, const Common::ADParams &p continue; } - // Try to open all files for this game + // Try to match all files for this game for (fileDesc = g->filesDescriptions; fileDesc->fileName; fileDesc++) { tstr = fileDesc->fileName; tstr.toLowercase(); - tstr2 = tstr + "."; - if (!filesMD5.contains(tstr) && !filesMD5.contains(tstr2)) { + if (!filesMD5.contains(tstr)) { fileMissing = true; break; } if (fileDesc->md5 != NULL) { - if (strcmp(fileDesc->md5, filesMD5[tstr].c_str()) && strcmp(fileDesc->md5, filesMD5[tstr2].c_str())) { + if (fileDesc->md5 != filesMD5[tstr]) { debug(3, "MD5 Mismatch. Skipping (%s) (%s)", fileDesc->md5, filesMD5[tstr].c_str()); fileMissing = true; break; @@ -360,7 +360,7 @@ static ADGameDescList detectGame(const FSList *fslist, const Common::ADParams &p } if (fileDesc->fileSize != -1) { - if (fileDesc->fileSize != filesSize[tstr] && fileDesc->fileSize != filesSize[tstr2]) { + if (fileDesc->fileSize != filesSize[tstr]) { debug(3, "Size Mismatch. Skipping"); fileMissing = true; break; @@ -378,7 +378,7 @@ static ADGameDescList detectGame(const FSList *fslist, const Common::ADParams &p int curFilesMatched = 0; for (fileDesc = g->filesDescriptions; fileDesc->fileName; fileDesc++) curFilesMatched++; - + if (curFilesMatched > maxFilesMatched) { debug(2, " ... new best match, removing all previous candidates"); maxFilesMatched = curFilesMatched; @@ -416,26 +416,23 @@ static ADGameDescList detectGame(const FSList *fslist, const Common::ADParams &p printf("\n"); } + // Filename based fallback if (params.fileBasedFallback != 0) { const ADFileBasedFallback *ptr = params.fileBasedFallback; const char* const* filenames = 0; // First we create list of files required for detection. - if (allFiles.empty()) { - File testFile; - - for (; ptr->desc; ptr++) { - filenames = ptr->filenames; - for (; *filenames; filenames++) { - tstr = String(*filenames); - tstr.toLowercase(); - - if (!allFiles.contains(tstr)) { - if (testFile.open(tstr)) { - tstr2 = tstr + "."; - allFiles[tstr] = allFiles[tstr2] = 1; - testFile.close(); - } + // The filenames can be different than the MD5 based match ones. + for (; ptr->desc; ptr++) { + filenames = ptr->filenames; + for (; *filenames; filenames++) { + tstr = String(*filenames); + tstr.toLowercase(); + + if (!allFiles.contains(tstr)) { + if (testFile.open(tstr) || testFile.open(tstr + ".")) { + allFiles[tstr] = true; + testFile.close(); } } } @@ -461,12 +458,10 @@ static ADGameDescList detectGame(const FSList *fslist, const Common::ADParams &p } tstr = String(*filenames); - tstr.toLowercase(); - tstr2 = tstr + "."; debug(3, "++ %s", *filenames); - if (!allFiles.contains(tstr) && !allFiles.contains(tstr2)) { + if (!allFiles.contains(tstr)) { fileMissing = true; continue; } diff --git a/common/algorithm.h b/common/algorithm.h new file mode 100644 index 0000000000..616dc67317 --- /dev/null +++ b/common/algorithm.h @@ -0,0 +1,103 @@ +/* ScummVM - Scumm Interpreter + * Copyright (C) 2007 The ScummVM project + * + * 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. + * + * $URL$ + * $Id$ + */ + +#ifndef COMMON_ALGORITHM_H +#define COMMON_ALGORITHM_H + +#include "common/scummsys.h" + +namespace Common { + +template<class In, class Out> +Out copy(In first, In last, Out dst) { + while (first != last) + *dst++ = *first++; + return dst; +} + +template<class In, class Out> +Out copy_backward(In first, In last, Out dst) { + while (first != last) + *--dst = *--last; + return dst; +} + +template<class In, class Out, class Op> +Out copy_if(In first, In last, Out dst, Op op) { + while (first != last) { + if (op(*first)) + *dst++ = *first; + ++first; + } + return dst; +} + +template<class In, class T> +In find(In first, In last, const T &v) { + while (first != last) { + if (*first == v) + return first; + ++first; + } + return last; +} + +template<class In, class Pred> +In find_if(In first, In last, Pred p) { + while (first != last) { + if (p(*first)) + return first; + ++first; + } + return last; +} + +template<class In, class Op> +Op for_each(In first, In last, Op f) { + while (first != last) f(*first++); + return f; +} + +// Simple sort function, modelled after std::sort. +// Use it like this: sort(container.begin(), container.end()). +// Also work on plain old int arrays etc. +template<class T> +void sort(T first, T last) { + if (first == last) + return; + + // Simple selection sort + T i(first); + for (; i != last; ++i) { + T minElem(i); + T j(i); + ++j; + for (; j != last; ++j) + if (*j < *minElem) + minElem = j; + if (minElem != i) + SWAP(*minElem, *i); + } +} + +} // end of namespace Common +#endif + diff --git a/common/array.h b/common/array.h index d0be7fa194..97ee6abdf4 100644 --- a/common/array.h +++ b/common/array.h @@ -23,6 +23,7 @@ #define COMMON_ARRAY_H #include "common/scummsys.h" +#include "common/algorithm.h" namespace Common { @@ -37,14 +38,15 @@ public: typedef T *iterator; typedef const T *const_iterator; + typedef T value_type; + public: Array() : _capacity(0), _size(0), _data(0) {} Array(const Array<T>& array) : _capacity(0), _size(0), _data(0) { _size = array._size; _capacity = _size + 32; _data = new T[_capacity]; - for (int i = 0; i < _size; i++) - _data[i] = array._data[i]; + copy(array._data, array._data + _size, _data); } ~Array() { @@ -59,21 +61,14 @@ public: void push_back(const Array<T>& array) { ensureCapacity(_size + array._size); - for (int i = 0; i < array._size; i++) - _data[_size++] = array._data[i]; + copy(array._data, array._data + array._size, _data + _size); + _size += array._size; } void insert_at(int idx, const T& element) { assert(idx >= 0 && idx <= _size); ensureCapacity(_size + 1); - // The following loop is not efficient if you can just memcpy things around. - // e.g. if you have a list of ints. But for real objects (String...), memcpy - // usually isn't correct (specifically, for any class which has a non-default - // copy behaviour. E.g. the String class uses a refCounter which has to be - // updated whenever a String is copied. - for (int i = _size; i > idx; i--) { - _data[i] = _data[i-1]; - } + copy_backward(_data + idx, _data + _size, _data + _size + 1); _data[idx] = element; _size++; } @@ -81,8 +76,7 @@ public: T remove_at(int idx) { assert(idx >= 0 && idx < _size); T tmp = _data[idx]; - for (int i = idx; i < _size - 1; i++) - _data[i] = _data[i+1]; + copy(_data + idx + 1, _data + _size, _data + idx); _size--; return tmp; } @@ -108,8 +102,7 @@ public: _size = array._size; _capacity = _size + 32; _data = new T[_capacity]; - for (int i = 0; i < _size; i++) - _data[i] = array._data[i]; + copy(array._data, array._data + _size, _data); return *this; } @@ -149,11 +142,7 @@ public: } bool contains(const T &key) const { - for (const_iterator i = begin(); i != end(); ++i) { - if (*i == key) - return true; - } - return false; + return find(begin(), end(), key) != end(); } @@ -168,8 +157,7 @@ protected: if (old_data) { // Copy old data - for (int i = 0; i < _size; i++) - _data[i] = old_data[i]; + copy(old_data, old_data + _size, _data); delete [] old_data; } } diff --git a/common/config-manager.cpp b/common/config-manager.cpp index f8426f18d0..41f3c1a7e9 100644 --- a/common/config-manager.cpp +++ b/common/config-manager.cpp @@ -33,8 +33,6 @@ #include "common/file.h" #include "common/util.h" -DECLARE_SINGLETON(Common::ConfigManager); - #ifdef __PLAYSTATION2__ #include "backends/platform/ps2/systemps2.h" #endif diff --git a/common/endian.h b/common/endian.h index 173605dde4..c2e9267b58 100644 --- a/common/endian.h +++ b/common/endian.h @@ -131,7 +131,7 @@ FORCEINLINE uint16 SWAP_BYTES_16(uint16 a) { #endif -#if defined(SCUMM_NEED_ALIGNMENT) || defined(SCUMM_BIG_ENDIAN) +#if defined(SCUMM_NEED_ALIGNMENT) || !defined(SCUMM_LITTLE_ENDIAN) FORCEINLINE uint16 READ_LE_UINT16(const void *ptr) { const byte *b = (const byte *)ptr; return (b[1] << 8) + b[0]; @@ -168,7 +168,7 @@ FORCEINLINE uint16 SWAP_BYTES_16(uint16 a) { #endif -#if defined(SCUMM_NEED_ALIGNMENT) || defined(SCUMM_LITTLE_ENDIAN) +#if defined(SCUMM_NEED_ALIGNMENT) || !defined(SCUMM_BIG_ENDIAN) FORCEINLINE uint16 READ_BE_UINT16(const void *ptr) { const byte *b = (const byte *)ptr; return (b[0] << 8) + b[1]; diff --git a/common/func.h b/common/func.h index b644f6569b..19d0ceafec 100644 --- a/common/func.h +++ b/common/func.h @@ -26,16 +26,219 @@ namespace Common { -template <class T> -struct EqualTo { - bool operator()(const T& x, const T& y) const { return x == y; } +template<class Arg, class Result> +struct UnaryFunction { + typedef Arg ArgumenType; + typedef Result ResultType; }; -template <class T> -struct Less { - bool operator()(const T& x, const T& y) const { return x < y; } +template<class Arg1, class Arg2, class Result> +struct BinaryFunction { + typedef Arg1 FirstArgumentType; + typedef Arg2 SecondArgumentType; + typedef Result ResultType; }; +template<class T> +struct EqualTo : public BinaryFunction<T, T, bool> { + bool operator()(const T& x, const T& y) const { return x == y; } +}; + +template<class T> +struct Less : public BinaryFunction<T, T, bool> { + bool operator()(const T& x, const T& y) const { return x < y; } +}; + +template<class Op> +class Binder1st : public UnaryFunction<typename Op::SecondArgumentType, typename Op::ResultType> { +private: + Op _op; + typename Op::FirstArgumentType _arg1; +public: + Binder1st(const Op &op, const typename Op::FirstArgumentType &arg1) : _op(op), _arg1(arg1) {} + + typename Op::ResultType operator()(typename Op::SecondArgumentType v) const { + return _op(_arg1, v); + } +}; + +template<class Op, class T> +inline Binder1st<Op> bind1st(const Op &op, const T &t) { + return Binder1st<Op>(op, t); +} + +template<class Op> +class Binder2nd : public UnaryFunction<typename Op::FirstArgumentType, typename Op::ResultType> { +private: + Op _op; + typename Op::SecondArgumentType _arg2; +public: + Binder2nd(const Op &op, const typename Op::SecondArgumentType &arg2) : _op(op), _arg2(arg2) {} + + typename Op::ResultType operator()(typename Op::FirstArgumentType v) const { + return _op(v, _arg2); + } +}; + +template<class Op, class T> +inline Binder2nd<Op> bind2nd(const Op &op, const T &t) { + return Binder2nd<Op>(op, t); +} + +template<class Arg, class Result> +class PointerToUnaryFunc : public UnaryFunction<Arg, Result> { +private: + Result (*_func)(Arg); +public: + typedef Result (*FuncType)(Arg); + + PointerToUnaryFunc(const FuncType &func) : _func(func) {} + Result operator()(Arg v) const { + return _func(v); + } +}; + +template<class Arg1, class Arg2, class Result> +class PointerToBinaryFunc : public BinaryFunction<Arg1, Arg2, Result> { +private: + Result (*_func)(Arg1, Arg2); +public: + typedef Result (*FuncType)(Arg1, Arg2); + + PointerToBinaryFunc(const FuncType &func) : _func(func) {} + Result operator()(Arg1 v1, Arg2 v2) const { + return _func(v1, v2); + } +}; + +template<class Arg, class Result> +inline PointerToUnaryFunc<Arg, Result> ptr_fun(Result (*func)(Arg)) { + return PointerToUnaryFunc<Arg, Result>(func); +} + +template<class Arg1, class Arg2, class Result> +inline PointerToBinaryFunc<Arg1, Arg2, Result> ptr_fun(Result (*func)(Arg1, Arg2)) { + return PointerToBinaryFunc<Arg1, Arg2, Result>(func); +} + +template<class Result, class T> +class MemFunc0 : public UnaryFunction<T*, Result> { +private: + Result (T::*_func)(); +public: + typedef Result (T::*FuncType)(); + + MemFunc0(const FuncType &func) : _func(func) {} + Result operator()(T *v) const { + return (v->*_func)(); + } +}; + +template<class Result, class T> +class ConstMemFunc0 : public UnaryFunction<T*, Result> { +private: + Result (T::*_func)() const; +public: + typedef Result (T::*FuncType)() const; + + ConstMemFunc0(const FuncType &func) : _func(func) {} + Result operator()(T *v) const { + return (v->*_func)(); + } +}; + +template<class Result, class Arg, class T> +class MemFunc1 : public BinaryFunction<T*, Arg, Result> { +private: + Result (T::*_func)(Arg); +public: + typedef Result (T::*FuncType)(Arg); + + MemFunc1(const FuncType &func) : _func(func) {} + Result operator()(T *v1, Arg v2) const { + return (v1->*_func)(v2); + } +}; + +template<class Result, class Arg, class T> +class ConstMemFunc1 : public BinaryFunction<T*, Arg, Result> { +private: + Result (T::*_func)(Arg) const; +public: + typedef Result (T::*FuncType)(Arg) const; + + ConstMemFunc1(const FuncType &func) : _func(func) {} + Result operator()(T *v1, Arg v2) const { + return (v1->*_func)(v2); + } +}; + +template<class Result, class T> +inline MemFunc0<Result, T> mem_fun(Result (T::*f)()) { + return MemFunc0<Result, T>(f); +} + +template<class Result, class T> +inline ConstMemFunc0<Result, T> mem_fun(Result (T::*f)() const) { + return ConstMemFunc0<Result, T>(f); +} + +template<class Result, class Arg, class T> +inline MemFunc1<Result, Arg, T> mem_fun(Result (T::*f)(Arg)) { + return MemFunc1<Result, Arg, T>(f); +} + +template<class Result, class Arg, class T> +inline ConstMemFunc1<Result, Arg, T> mem_fun(Result (T::*f)(Arg) const) { + return ConstMemFunc1<Result, Arg, T>(f); +} + +template<class Cont> +class BackInsertIterator { +private: + Cont *_container; + +public: + BackInsertIterator(Cont &c) : _container(&c) {} + + BackInsertIterator &operator =(const typename Cont::value_type &v) { + _container->push_back(v); + return *this; + } + + BackInsertIterator &operator *() { return *this; } + BackInsertIterator &operator ++() { return *this; } + BackInsertIterator operator ++(int) { return *this; } +}; + +template<class Cont> +BackInsertIterator<Cont> back_inserter(Cont &c) { + return BackInsertIterator<Cont>(c); +} + +template<class Cont> +class FrontInsertIterator { +private: + Cont *_container; + +public: + FrontInsertIterator(Cont &c) : _container(&c) {} + + FrontInsertIterator &operator =(const typename Cont::value_type &v) { + _container->push_front(v); + return *this; + } + + FrontInsertIterator &operator *() { return *this; } + FrontInsertIterator &operator ++() { return *this; } + FrontInsertIterator operator ++(int) { return *this; } +}; + +template<class Cont> +FrontInsertIterator<Cont> front_inserter(Cont &c) { + return FrontInsertIterator<Cont>(c); +} + /** * Base template for hash functor objects, used by HashMap. * This needs to be specialized for every type that you need to hash. @@ -61,30 +264,7 @@ GENERATE_TRIVIAL_HASH_FUNCTOR(unsigned long); #undef GENERATE_TRIVIAL_HASH_FUNCTOR - -// Simple sort function, modelled after std::sort. -// Use it like this: sort(container.begin(), container.end()). -// Also work on plain old int arrays etc. -template <typename T> -void sort(T first, T last) { - if (first == last) - return; - - // Simple selection sort - T i(first); - for (; i != last; ++i) { - T minElem(i); - T j(i); - ++j; - for (; j != last; ++j) - if (*j < *minElem) - minElem = j; - if (minElem != i) - SWAP(*minElem, *i); - } -} - - } // End of namespace Common #endif + diff --git a/common/hash-str.h b/common/hash-str.h index bb61e3091d..99ebf99a10 100644 --- a/common/hash-str.h +++ b/common/hash-str.h @@ -29,6 +29,8 @@ namespace Common { uint hashit(const char *str); uint hashit_lower(const char *str); // Generate a hash based on the lowercase version of the string +inline uint hashit(const String &str) { return hashit(str.c_str()); } +inline uint hashit_lower(const String &str) { return hashit_lower(str.c_str()); } // FIXME: The following functors obviously are not consistently named diff --git a/common/iff_container.h b/common/iff_container.h new file mode 100644 index 0000000000..730163254f --- /dev/null +++ b/common/iff_container.h @@ -0,0 +1,228 @@ +/* ScummVM - Scumm Interpreter + * Copyright (C) 2006 The ScummVM project + * + * 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. + * + * $URL$ + * $Id$ + */ + +#ifndef COMMON_IFF_CONTAINER_H +#define COMMON_IFF_CONTAINER_H + +#include "common/stdafx.h" +#include "common/scummsys.h" +#include "common/endian.h" +#include "common/stream.h" +#include "common/util.h" + +namespace Common { + +typedef uint32 IFF_ID; + +#define ID_FORM MKID_BE('FORM') +/* EA IFF 85 group identifier */ +#define ID_CAT MKID_BE('CAT ') +/* EA IFF 85 group identifier */ +#define ID_LIST MKID_BE('LIST') +/* EA IFF 85 group identifier */ +#define ID_PROP MKID_BE('PROP') +/* EA IFF 85 group identifier */ +#define ID_END MKID_BE('END ') +/* unofficial END-of-FORM identifier (see Amiga RKM Devices Ed.3 +page 376) */ +#define ID_ILBM MKID_BE('ILBM') +/* EA IFF 85 raster bitmap form */ +#define ID_DEEP MKID_BE('DEEP') +/* Chunky pixel image files (Used in TV Paint) */ +#define ID_RGB8 MKID_BE('RGB8') +/* RGB image forms, Turbo Silver (Impulse) */ +#define ID_RGBN MKID_BE('RGBN') +/* RGB image forms, Turbo Silver (Impulse) */ +#define ID_PBM MKID_BE('PBM ') +/* 256-color chunky format (DPaint 2 ?) */ +#define ID_ACBM MKID_BE('ACBM') +/* Amiga Contiguous Bitmap (AmigaBasic) */ +#define ID_8SVX MKID_BE('8SVX') +/* Amiga 8 bits voice */ + +/* generic */ + +#define ID_FVER MKID_BE('FVER') +/* AmigaOS version string */ +#define ID_JUNK MKID_BE('JUNK') +/* always ignore this chunk */ +#define ID_ANNO MKID_BE('ANNO') +/* EA IFF 85 Generic Annotation chunk */ +#define ID_AUTH MKID_BE('AUTH') +/* EA IFF 85 Generic Author chunk */ +#define ID_CHRS MKID_BE('CHRS') +/* EA IFF 85 Generic character string chunk */ +#define ID_NAME MKID_BE('NAME') +/* EA IFF 85 Generic Name of art, music, etc. chunk */ +#define ID_TEXT MKID_BE('TEXT') +/* EA IFF 85 Generic unformatted ASCII text chunk */ +#define ID_copy MKID_BE('(c) ') +/* EA IFF 85 Generic Copyright text chunk */ + +/* ILBM chunks */ + +#define ID_BMHD MKID_BE('BMHD') +/* ILBM BitmapHeader */ +#define ID_CMAP MKID_BE('CMAP') +/* ILBM 8bit RGB colormap */ +#define ID_GRAB MKID_BE('GRAB') +/* ILBM "hotspot" coordiantes */ +#define ID_DEST MKID_BE('DEST') +/* ILBM destination image info */ +#define ID_SPRT MKID_BE('SPRT') +/* ILBM sprite identifier */ +#define ID_CAMG MKID_BE('CAMG') +/* Amiga viewportmodes */ +#define ID_BODY MKID_BE('BODY') +/* ILBM image data */ +#define ID_CRNG MKID_BE('CRNG') +/* color cycling */ +#define ID_CCRT MKID_BE('CCRT') +/* color cycling */ +#define ID_CLUT MKID_BE('CLUT') +/* Color Lookup Table chunk */ +#define ID_DPI MKID_BE('DPI ') +/* Dots per inch chunk */ +#define ID_DPPV MKID_BE('DPPV') +/* DPaint perspective chunk (EA) */ +#define ID_DRNG MKID_BE('DRNG') +/* DPaint IV enhanced color cycle chunk (EA) */ +#define ID_EPSF MKID_BE('EPSF') +/* Encapsulated Postscript chunk */ +#define ID_CMYK MKID_BE('CMYK') +/* Cyan, Magenta, Yellow, & Black color map (Soft-Logik) */ +#define ID_CNAM MKID_BE('CNAM') +/* Color naming chunk (Soft-Logik) */ +#define ID_PCHG MKID_BE('PCHG') +/* Line by line palette control information (Sebastiano Vigna) */ +#define ID_PRVW MKID_BE('PRVW') +/* A mini duplicate ILBM used for preview (Gary Bonham) */ +#define ID_XBMI MKID_BE('XBMI') +/* eXtended BitMap Information (Soft-Logik) */ +#define ID_CTBL MKID_BE('CTBL') +/* Newtek Dynamic Ham color chunk */ +#define ID_DYCP MKID_BE('DYCP') +/* Newtek Dynamic Ham chunk */ +#define ID_SHAM MKID_BE('SHAM') +/* Sliced HAM color chunk */ +#define ID_ABIT MKID_BE('ABIT') +/* ACBM body chunk */ +#define ID_DCOL MKID_BE('DCOL') +/* unofficial direct color */ +#define ID_DPPS MKID_BE('DPPS') +/* ? */ +#define ID_TINY MKID_BE('TINY') +/* ? */ +#define ID_DPPV MKID_BE('DPPV') +/* ? */ + +/* 8SVX chunks */ + +#define ID_VHDR MKID_BE('VHDR') +/* 8SVX Voice8Header */ + + +char * ID2string(Common::IFF_ID id); + + +class IFFChunk : public Common::ReadStream { + +protected: + Common::ReadStream *_input; + uint32 bytesRead; + +public: + IFF_ID id; + uint32 size; + + IFFChunk(Common::ReadStream *input): _input(input) { + size = bytesRead = 0; + } + + void incBytesRead(uint32 inc) { + bytesRead += inc; + if (bytesRead > size) { + error("Chunk overead"); + } + } + + void readHeader() { + id = _input->readUint32BE(); + size = _input->readUint32BE(); + bytesRead = 0; + } + + void feed() { + if (size % 2) { + size++; + } + while (!_input->eos() && !eos()) { + readByte(); + } + } + + // Common::ReadStream implementation + bool eos() const { + return (size - bytesRead) == 0; + } + + uint32 read(void *dataPtr, uint32 dataSize) { + incBytesRead(dataSize); + return _input->read(dataPtr, dataSize); + } + +}; + +class IFFParser { +public: + IFFParser(Common::ReadStream &input) : _formChunk(&input), _chunk(&input) { + _formChunk.readHeader(); + if (_formChunk.id != ID_FORM) { + error("IFFDecoder input is not a FORM type IFF file"); + } + _typeId = _formChunk.readUint32BE(); + } + + virtual ~IFFParser() {} + + IFFChunk *nextChunk() { + _chunk.feed(); + _formChunk.incBytesRead(_chunk.size); + + if (_formChunk.eos()) + return 0; + + _formChunk.incBytesRead(8); + _chunk.readHeader(); + + return &_chunk; + } + + IFF_ID _typeId; + +protected: + IFFChunk _formChunk; + IFFChunk _chunk; +}; + +} // namespace Common + +#endif diff --git a/common/list.h b/common/list.h index da20f22cf1..68a464d194 100644 --- a/common/list.h +++ b/common/list.h @@ -111,8 +111,10 @@ public: NodeBase *_anchor; public: - typedef Iterator<T> iterator; - typedef Iterator<const T> const_iterator; + typedef Iterator<T> iterator; + typedef Iterator<const T> const_iterator; + + typedef T value_type; public: List() { diff --git a/common/rect.h b/common/rect.h index 7751d9a84a..be1035669a 100644 --- a/common/rect.h +++ b/common/rect.h @@ -36,9 +36,9 @@ struct Point { int16 x; //!< The horizontal part of the point int16 y; //!< The vertical part of the point - Point() : x(0), y(0) {}; - Point(const Point &p) : x(p.x), y(p.y) {}; - explicit Point(int16 x1, int16 y1) : x(x1), y(y1) {}; + Point() : x(0), y(0) {} + Point(const Point &p) : x(p.x), y(p.y) {} + explicit Point(int16 x1, int16 y1) : x(x1), y(y1) {} Point & operator=(const Point & p) { x = p.x; y = p.y; return *this; }; bool operator==(const Point & p) const { return x == p.x && y == p.y; }; bool operator!=(const Point & p) const { return x != p.x || y != p.y; }; diff --git a/common/scummsys.h b/common/scummsys.h index 94593bf03b..0ba3f67bd8 100644 --- a/common/scummsys.h +++ b/common/scummsys.h @@ -203,27 +203,31 @@ #elif defined(__PALMOS_TRAPS__) || defined (__PALMOS_ARMLET__) - #define scumm_stricmp stricmp - #define scumm_strnicmp strnicmp - #ifdef PALMOS_68K - #define SCUMM_BIG_ENDIAN + # include "globals.h" + # define SCUMM_BIG_ENDIAN + + # define scumm_stricmp StrCaselessCompare + # define scumm_strnicmp StrNCaselessCompare + #else - #define SCUMM_LITTLE_ENDIAN + + # include <extras_string.h> + # define SCUMM_LITTLE_ENDIAN + + # define scumm_stricmp stricmp + # define scumm_strnicmp strnicmp #endif #define SCUMM_NEED_ALIGNMENT - - #include "palmversion.h" - #include "globals.h" - #include "extend.h" - #define STRINGBUFLEN 256 + + extern const char *SCUMMVM_SAVEPATH; #if !defined(COMPILE_ZODIAC) && !defined(COMPILE_OS5) - #define NEWGUI_256 + # define NEWGUI_256 #else - #undef UNUSED + # undef UNUSED #endif #elif defined(__MORPHOS__) diff --git a/common/singleton.h b/common/singleton.h index 5e72e72230..f26324999e 100644 --- a/common/singleton.h +++ b/common/singleton.h @@ -37,8 +37,6 @@ private: Singleton<T>(const Singleton<T>&); Singleton<T>& operator= (const Singleton<T>&); - static T* _singleton; - /** * The default object factory used by the template class Singleton. * By specialising this template function, one can make a singleton use a @@ -58,16 +56,13 @@ public: public: static T& instance() { - // TODO: We aren't thread safe. For now we ignore it since the - // only thing using this singleton template is the config manager, - // and that is first instantiated long before any threads. + // TODO: We aren't thread safe. // TODO: We don't leak, but the destruction order is nevertheless // semi-random. If we use multiple singletons, the destruction // order might become an issue. There are various approaches // to solve that problem, but for now this is sufficient - if (!_singleton) - _singleton = T::makeInstance(); - return *_singleton; + static T *instance = T::makeInstance(); + return *instance; } protected: Singleton<T>() { } @@ -80,8 +75,6 @@ protected: typedef T SingletonBaseType; }; -#define DECLARE_SINGLETON(T) template<> T* Common::Singleton<T>::_singleton=0 - } // End of namespace Common #endif diff --git a/common/str.cpp b/common/str.cpp index 31cbb7cd22..e5272bd133 100644 --- a/common/str.cpp +++ b/common/str.cpp @@ -211,6 +211,11 @@ bool String::hasSuffix(const char *x) const { return *x == 0; } +bool String::contains(const char *x) const { + assert(x != 0); + return strstr(c_str(), x) != NULL; +} + void String::deleteLastChar() { deleteChar(_len - 1); } diff --git a/common/str.h b/common/str.h index 16122b579f..9fbb6734f5 100644 --- a/common/str.h +++ b/common/str.h @@ -125,10 +125,10 @@ public: int compareTo(const char *x) const; // strcmp clone int compareToIgnoreCase(const char *x) const; // stricmp clone - - bool hasSuffix(const char *x) const; bool hasPrefix(const char *x) const; + + bool contains(const char *x) const; inline const char *c_str() const { return _str; } inline uint size() const { return _len; } diff --git a/common/system.h b/common/system.h index 4f2f1c37fe..c1ff066095 100644 --- a/common/system.h +++ b/common/system.h @@ -352,14 +352,14 @@ public: * of the relevant methods simply do nothing. * @see endGFXTransaction */ - virtual void beginGFXTransaction() {}; + virtual void beginGFXTransaction() {} /** * End (and thereby commit) the current GFX transaction. * @see beginGFXTransaction */ - virtual void endGFXTransaction() {}; + virtual void endGFXTransaction() {} /** @@ -656,7 +656,7 @@ public: * @see setPalette * @see kFeatureCursorHasPalette */ - virtual void setCursorPalette(const byte *colors, uint start, uint num) {}; + virtual void setCursorPalette(const byte *colors, uint start, uint num) {} /** * Disable or enable cursor palette. @@ -668,7 +668,7 @@ public: * @see setPalette * @see kFeatureCursorHasPalette */ - virtual void disableCursorPalette(bool disable) {}; + virtual void disableCursorPalette(bool disable) {} //@} diff --git a/common/util.cpp b/common/util.cpp index 6089681484..5e5d719e31 100644 --- a/common/util.cpp +++ b/common/util.cpp @@ -144,24 +144,24 @@ uint RandomSource::getRandomNumberRng(uint min, uint max) { const LanguageDescription g_languages[] = { + {"zh", "Chinese (Taiwan)", ZH_TWN}, + {"cz", "Czech", CZ_CZE}, + {"nl", "Dutch", NL_NLD}, {"en", "English", EN_ANY}, // Generic English (when only one game version exist) - {"us", "English (US)", EN_USA}, {"gb", "English (GB)", EN_GRB}, - {"de", "German", DE_DEU}, + {"us", "English (US)", EN_USA}, {"fr", "French", FR_FRA}, + {"de", "German", DE_DEU}, + {"hb", "Hebrew", HB_ISR}, {"it", "Italian", IT_ITA}, - {"br", "Portuguese", PT_BRA}, - {"es", "Spanish", ES_ESP}, {"jp", "Japanese", JA_JPN}, - {"zh", "Chinese (Taiwan)", ZH_TWN}, {"kr", "Korean", KO_KOR}, - {"se", "Swedish", SE_SWE}, - {"hb", "Hebrew", HB_ISR}, - {"ru", "Russian", RU_RUS}, - {"cz", "Czech", CZ_CZE}, - {"nl", "Dutch", NL_NLD}, {"nb", "Norwegian Bokm\xE5l", NB_NOR}, {"pl", "Polish", PL_POL}, + {"br", "Portuguese", PT_BRA}, + {"ru", "Russian", RU_RUS}, + {"es", "Spanish", ES_ESP}, + {"se", "Swedish", SE_SWE}, {0, 0, UNK_LANG} }; @@ -415,12 +415,10 @@ static void debugHelper(const char *in_buf, bool caret = true) { strcpy(buf, in_buf); } -#ifndef _WIN32_WCE if (caret) printf("%s\n", buf); else printf("%s", buf); -#endif #if defined( USE_WINDBG ) if (caret) @@ -551,6 +549,7 @@ void NORETURN CDECL error(const char *s, ...) { #endif #ifdef PALMOS_MODE + extern void PalmFatalError(const char *err); PalmFatalError(buf_output); #endif diff --git a/common/util.h b/common/util.h index da76bd7220..d6cfeca89f 100644 --- a/common/util.h +++ b/common/util.h @@ -89,25 +89,24 @@ public: * List of game language. */ enum Language { + ZH_TWN, + CZ_CZE, + NL_NLD, EN_ANY, // Generic English (when only one game version exist) - EN_USA, EN_GRB, - - DE_DEU, + EN_USA, FR_FRA, + DE_DEU, + HB_ISR, IT_ITA, - PT_BRA, - ES_ESP, JA_JPN, - ZH_TWN, KO_KOR, - SE_SWE, - HB_ISR, - RU_RUS, - CZ_CZE, - NL_NLD, NB_NOR, PL_POL, + PT_BRA, + RU_RUS, + ES_ESP, + SE_SWE, UNK_LANG = -1 // Use default language (i.e. none specified) }; |