diff options
author | Matthew Hoops | 2011-08-26 22:44:17 -0400 |
---|---|---|
committer | Matthew Hoops | 2011-08-26 22:44:17 -0400 |
commit | 4a69dc13d92e82fff85dc5a3a923b74ced259ffa (patch) | |
tree | 8945cd3745fd65f28b043caf7b1beddbbce2b2a1 /common | |
parent | ad293b249e74dd1cfbdbd721d02145efbdaf9eca (diff) | |
parent | 5e174cbfe466dbbe8e5470b0a00de1481b986181 (diff) | |
download | scummvm-rg350-4a69dc13d92e82fff85dc5a3a923b74ced259ffa.tar.gz scummvm-rg350-4a69dc13d92e82fff85dc5a3a923b74ced259ffa.tar.bz2 scummvm-rg350-4a69dc13d92e82fff85dc5a3a923b74ced259ffa.zip |
Merge remote branch 'upstream/master' into pegasus
Diffstat (limited to 'common')
50 files changed, 675 insertions, 251 deletions
diff --git a/common/EventDispatcher.cpp b/common/EventDispatcher.cpp index e97068c0d0..4e3f671cfd 100644 --- a/common/EventDispatcher.cpp +++ b/common/EventDispatcher.cpp @@ -28,12 +28,12 @@ EventDispatcher::EventDispatcher() : _mapper(0) { } EventDispatcher::~EventDispatcher() { - for (Common::List<SourceEntry>::iterator i = _sources.begin(); i != _sources.end(); ++i) { + for (List<SourceEntry>::iterator i = _sources.begin(); i != _sources.end(); ++i) { if (i->autoFree) delete i->source; } - for (Common::List<ObserverEntry>::iterator i = _observers.begin(); i != _observers.end(); ++i) { + for (List<ObserverEntry>::iterator i = _observers.begin(); i != _observers.end(); ++i) { if (i->autoFree) delete i->observer; } @@ -43,9 +43,11 @@ EventDispatcher::~EventDispatcher() { } void EventDispatcher::dispatch() { - Common::Event event; + Event event; - for (Common::List<SourceEntry>::iterator i = _sources.begin(); i != _sources.end(); ++i) { + dispatchPoll(); + + for (List<SourceEntry>::iterator i = _sources.begin(); i != _sources.end(); ++i) { const bool allowMapping = i->source->allowMapping(); while (i->source->pollEvent(event)) { @@ -83,7 +85,7 @@ void EventDispatcher::registerSource(EventSource *source, bool autoFree) { } void EventDispatcher::unregisterSource(EventSource *source) { - for (Common::List<SourceEntry>::iterator i = _sources.begin(); i != _sources.end(); ++i) { + for (List<SourceEntry>::iterator i = _sources.begin(); i != _sources.end(); ++i) { if (i->source == source) { if (i->autoFree) delete source; @@ -94,14 +96,15 @@ void EventDispatcher::unregisterSource(EventSource *source) { } } -void EventDispatcher::registerObserver(EventObserver *obs, uint priority, bool autoFree) { +void EventDispatcher::registerObserver(EventObserver *obs, uint priority, bool autoFree, bool notifyPoll) { ObserverEntry newEntry; newEntry.observer = obs; newEntry.priority = priority; newEntry.autoFree = autoFree; + newEntry.poll = notifyPoll; - for (Common::List<ObserverEntry>::iterator i = _observers.begin(); i != _observers.end(); ++i) { + for (List<ObserverEntry>::iterator i = _observers.begin(); i != _observers.end(); ++i) { if (i->priority < priority) { _observers.insert(i, newEntry); return; @@ -112,7 +115,7 @@ void EventDispatcher::registerObserver(EventObserver *obs, uint priority, bool a } void EventDispatcher::unregisterObserver(EventObserver *obs) { - for (Common::List<ObserverEntry>::iterator i = _observers.begin(); i != _observers.end(); ++i) { + for (List<ObserverEntry>::iterator i = _observers.begin(); i != _observers.end(); ++i) { if (i->observer == obs) { if (i->autoFree) delete obs; @@ -124,11 +127,18 @@ void EventDispatcher::unregisterObserver(EventObserver *obs) { } void EventDispatcher::dispatchEvent(const Event &event) { - for (Common::List<ObserverEntry>::iterator i = _observers.begin(); i != _observers.end(); ++i) { + for (List<ObserverEntry>::iterator i = _observers.begin(); i != _observers.end(); ++i) { if (i->observer->notifyEvent(event)) break; } } -} // End of namespace Common +void EventDispatcher::dispatchPoll() { + for (List<ObserverEntry>::iterator i = _observers.begin(); i != _observers.end(); ++i) { + if (i->poll == true) + if (i->observer->notifyPoll()) + break; + } +} +} // End of namespace Common diff --git a/common/EventRecorder.cpp b/common/EventRecorder.cpp index 4441070050..5e24f128c3 100644 --- a/common/EventRecorder.cpp +++ b/common/EventRecorder.cpp @@ -22,6 +22,7 @@ #include "common/EventRecorder.h" +#include "common/bufferedstream.h" #include "common/config-manager.h" #include "common/random.h" #include "common/savefile.h" @@ -34,7 +35,28 @@ DECLARE_SINGLETON(EventRecorder); #define RECORD_SIGNATURE 0x54455354 #define RECORD_VERSION 1 -void readRecord(SeekableReadStream *inFile, uint32 &diff, Event &event) { +uint32 readTime(ReadStream *inFile) { + uint32 d = inFile->readByte(); + if (d == 0xff) { + d = inFile->readUint32LE(); + } + + return d; +} + +void writeTime(WriteStream *outFile, uint32 d) { + //Simple RLE compression + if (d >= 0xff) { + outFile->writeByte(0xff); + outFile->writeUint32LE(d); + } else { + outFile->writeByte(d); + } +} + +void readRecord(SeekableReadStream *inFile, uint32 &diff, Event &event, uint32 &millis) { + millis = readTime(inFile); + diff = inFile->readUint32LE(); event.type = (EventType)inFile->readUint32LE(); @@ -53,6 +75,8 @@ void readRecord(SeekableReadStream *inFile, uint32 &diff, Event &event) { case EVENT_RBUTTONUP: case EVENT_WHEELUP: case EVENT_WHEELDOWN: + case EVENT_MBUTTONDOWN: + case EVENT_MBUTTONUP: event.mouse.x = inFile->readSint16LE(); event.mouse.y = inFile->readSint16LE(); break; @@ -61,7 +85,9 @@ void readRecord(SeekableReadStream *inFile, uint32 &diff, Event &event) { } } -void writeRecord(WriteStream *outFile, uint32 diff, const Event &event) { +void writeRecord(WriteStream *outFile, uint32 diff, const Event &event, uint32 millis) { + writeTime(outFile, millis); + outFile->writeUint32LE(diff); outFile->writeUint32LE((uint32)event.type); @@ -80,6 +106,8 @@ void writeRecord(WriteStream *outFile, uint32 diff, const Event &event) { case EVENT_RBUTTONUP: case EVENT_WHEELUP: case EVENT_WHEELDOWN: + case EVENT_MBUTTONDOWN: + case EVENT_MBUTTONUP: outFile->writeSint16LE(event.mouse.x); outFile->writeSint16LE(event.mouse.y); break; @@ -99,23 +127,31 @@ EventRecorder::EventRecorder() { _eventCount = 0; _lastEventCount = 0; _lastMillis = 0; + _lastEventMillis = 0; _recordMode = kPassthrough; } EventRecorder::~EventRecorder() { deinit(); + + g_system->deleteMutex(_timeMutex); + g_system->deleteMutex(_recorderMutex); } void EventRecorder::init() { String recordModeString = ConfMan.get("record_mode"); if (recordModeString.compareToIgnoreCase("record") == 0) { _recordMode = kRecorderRecord; + + debug(3, "EventRecorder: record"); } else { if (recordModeString.compareToIgnoreCase("playback") == 0) { _recordMode = kRecorderPlayback; + debug(3, "EventRecorder: playback"); } else { _recordMode = kPassthrough; + debug(3, "EventRecorder: passthrough"); } } @@ -136,8 +172,8 @@ void EventRecorder::init() { if (_recordMode == kRecorderRecord) { _recordCount = 0; _recordTimeCount = 0; - _recordFile = g_system->getSavefileManager()->openForSaving(_recordTempFileName); - _recordTimeFile = g_system->getSavefileManager()->openForSaving(_recordTimeFileName); + _recordFile = wrapBufferedWriteStream(g_system->getSavefileManager()->openForSaving(_recordTempFileName), 128 * 1024); + _recordTimeFile = wrapBufferedWriteStream(g_system->getSavefileManager()->openForSaving(_recordTimeFileName), 128 * 1024); _recordSubtitles = ConfMan.getBool("subtitles"); } @@ -146,8 +182,8 @@ void EventRecorder::init() { if (_recordMode == kRecorderPlayback) { _playbackCount = 0; _playbackTimeCount = 0; - _playbackFile = g_system->getSavefileManager()->openForLoading(_recordFileName); - _playbackTimeFile = g_system->getSavefileManager()->openForLoading(_recordTimeFileName); + _playbackFile = wrapBufferedSeekableReadStream(g_system->getSavefileManager()->openForLoading(_recordFileName), 128 * 1024, DisposeAfterUse::YES); + _playbackTimeFile = wrapBufferedSeekableReadStream(g_system->getSavefileManager()->openForLoading(_recordTimeFileName), 128 * 1024, DisposeAfterUse::YES); if (!_playbackFile) { warning("Cannot open playback file %s. Playback was switched off", _recordFileName.c_str()); @@ -173,6 +209,7 @@ void EventRecorder::init() { _recordCount = _playbackFile->readUint32LE(); _recordTimeCount = _playbackFile->readUint32LE(); + randomSourceCount = _playbackFile->readUint32LE(); for (uint i = 0; i < randomSourceCount; ++i) { RandomSourceRecord rec; @@ -190,10 +227,12 @@ void EventRecorder::init() { } g_system->getEventManager()->getEventDispatcher()->registerSource(this, false); - g_system->getEventManager()->getEventDispatcher()->registerObserver(this, 1, false); + g_system->getEventManager()->getEventDispatcher()->registerObserver(this, EventManager::kEventRecorderPriority, false, true); } void EventRecorder::deinit() { + debug(3, "EventRecorder: deinit"); + g_system->getEventManager()->getEventDispatcher()->unregisterSource(this); g_system->getEventManager()->getEventDispatcher()->unregisterObserver(this); @@ -236,8 +275,9 @@ void EventRecorder::deinit() { for (uint i = 0; i < _recordCount; ++i) { uint32 tempDiff; Event tempEvent; - readRecord(_playbackFile, tempDiff, tempEvent); - writeRecord(_recordFile, tempDiff, tempEvent); + uint32 millis; + readRecord(_playbackFile, tempDiff, tempEvent, millis); + writeRecord(_recordFile, tempDiff, tempEvent, millis); } _recordFile->finalize(); @@ -246,9 +286,6 @@ void EventRecorder::deinit() { //TODO: remove recordTempFileName'ed file } - - g_system->deleteMutex(_timeMutex); - g_system->deleteMutex(_recorderMutex); } void EventRecorder::registerRandomSource(RandomSource &rnd, const String &name) { @@ -278,23 +315,23 @@ void EventRecorder::processMillis(uint32 &millis) { g_system->lockMutex(_timeMutex); if (_recordMode == kRecorderRecord) { - //Simple RLE compression d = millis - _lastMillis; - if (d >= 0xff) { - _recordTimeFile->writeByte(0xff); - _recordTimeFile->writeUint32LE(d); - } else { - _recordTimeFile->writeByte(d); - } + writeTime(_recordTimeFile, d); + _recordTimeCount++; } if (_recordMode == kRecorderPlayback) { if (_recordTimeCount > _playbackTimeCount) { - d = _playbackTimeFile->readByte(); - if (d == 0xff) { - d = _playbackTimeFile->readUint32LE(); + d = readTime(_playbackTimeFile); + + while ((_lastMillis + d > millis) && (_lastMillis + d - millis > 50)) { + _recordMode = kPassthrough; + g_system->delayMillis(50); + millis = g_system->getMillis(); + _recordMode = kRecorderPlayback; } + millis = _lastMillis + d; _playbackTimeCount++; } @@ -304,6 +341,23 @@ void EventRecorder::processMillis(uint32 &millis) { g_system->unlockMutex(_timeMutex); } +bool EventRecorder::processDelayMillis(uint &msecs) { + if (_recordMode == kRecorderPlayback) { + _recordMode = kPassthrough; + + uint32 millis = g_system->getMillis(); + + _recordMode = kRecorderPlayback; + + if (_lastMillis > millis) { + // Skip delay if we're getting late + return true; + } + } + + return false; +} + bool EventRecorder::notifyEvent(const Event &ev) { if (_recordMode != kRecorderRecord) return false; @@ -311,15 +365,27 @@ bool EventRecorder::notifyEvent(const Event &ev) { StackLock lock(_recorderMutex); ++_eventCount; - writeRecord(_recordFile, _eventCount - _lastEventCount, ev); + writeRecord(_recordFile, _eventCount - _lastEventCount, ev, _lastMillis - _lastEventMillis); _recordCount++; _lastEventCount = _eventCount; + _lastEventMillis = _lastMillis; + + return false; +} + +bool EventRecorder::notifyPoll() { + if (_recordMode != kRecorderRecord) + return false; + + ++_eventCount; return false; } bool EventRecorder::pollEvent(Event &ev) { + uint32 millis; + if (_recordMode != kRecorderPlayback) return false; @@ -328,7 +394,7 @@ bool EventRecorder::pollEvent(Event &ev) { if (!_hasPlaybackEvent) { if (_recordCount > _playbackCount) { - readRecord(_playbackFile, const_cast<uint32&>(_playbackDiff), _playbackEvent); + readRecord(_playbackFile, const_cast<uint32&>(_playbackDiff), _playbackEvent, millis); _playbackCount++; _hasPlaybackEvent = true; } @@ -360,4 +426,3 @@ bool EventRecorder::pollEvent(Event &ev) { } } // End of namespace Common - diff --git a/common/EventRecorder.h b/common/EventRecorder.h index 8377d9e8bd..43a08b08cd 100644 --- a/common/EventRecorder.h +++ b/common/EventRecorder.h @@ -56,8 +56,12 @@ public: /** TODO: Add documentation, this is only used by the backend */ void processMillis(uint32 &millis); + /** TODO: Add documentation, this is only used by the backend */ + bool processDelayMillis(uint &msecs); + private: bool notifyEvent(const Event &ev); + bool notifyPoll(); bool pollEvent(Event &ev); bool allowMapping() const { return false; } @@ -72,6 +76,7 @@ private: volatile uint32 _recordCount; volatile uint32 _lastRecordEvent; volatile uint32 _recordTimeCount; + volatile uint32 _lastEventMillis; WriteStream *_recordFile; WriteStream *_recordTimeFile; MutexRef _timeMutex; @@ -103,4 +108,3 @@ private: } // End of namespace Common #endif - diff --git a/common/algorithm.h b/common/algorithm.h index 00c0e1c98f..e7ccef4840 100644 --- a/common/algorithm.h +++ b/common/algorithm.h @@ -226,12 +226,12 @@ void sort(T first, T last, StrictWeakOrdering comp) { */ template<typename T> void sort(T *first, T *last) { - sort(first, last, Common::Less<T>()); + sort(first, last, Less<T>()); } template<class T> void sort(T first, T last) { - sort(first, last, Common::Less<typename T::ValueType>()); + sort(first, last, Less<typename T::ValueType>()); } // MSVC is complaining about the minus operator being applied to an unsigned type @@ -269,4 +269,3 @@ T gcd(T a, T b) { } // End of namespace Common #endif - diff --git a/common/archive.cpp b/common/archive.cpp index 102d7aaa3f..954de8bcaa 100644 --- a/common/archive.cpp +++ b/common/archive.cpp @@ -147,7 +147,7 @@ void SearchSet::addSubDirectoriesMatching(const FSNode &directory, String origPa for (FSList::const_iterator i = subDirs.begin(); i != subDirs.end(); ++i) { String name = i->getName(); - if (Common::matchString(name.c_str(), pattern.c_str(), ignoreCase)) { + if (matchString(name.c_str(), pattern.c_str(), ignoreCase)) { matchIter = multipleMatches.find(name); if (matchIter == multipleMatches.end()) { multipleMatches[name] = true; @@ -288,4 +288,3 @@ void SearchManager::clear() { DECLARE_SINGLETON(SearchManager); } // namespace Common - diff --git a/common/archive.h b/common/archive.h index 8400c56d69..c8e78f9bc8 100644 --- a/common/archive.h +++ b/common/archive.h @@ -254,7 +254,7 @@ public: virtual void clear(); private: - friend class Common::Singleton<SingletonBaseType>; + friend class Singleton<SingletonBaseType>; SearchManager(); }; diff --git a/common/array.h b/common/array.h index e5434091fb..18cecfb98f 100644 --- a/common/array.h +++ b/common/array.h @@ -42,7 +42,7 @@ namespace Common { * management scheme. There, only elements that 'live' are actually constructed * (i.e., have their constructor called), and objects that are removed are * immediately destructed (have their destructor called). - * With Common::Array, this is not the case; instead, it simply uses new[] and + * With Array, this is not the case; instead, it simply uses new[] and * delete[] to allocate whole blocks of objects, possibly more than are * currently 'alive'. This simplifies memory management, but may have * undesirable side effects when one wants to use an Array of complex @@ -274,7 +274,7 @@ protected: if (capacity) { _storage = new T[capacity]; if (!_storage) - ::error("Common::Array: failure to allocate %d bytes", capacity); + ::error("Common::Array: failure to allocate %u bytes", capacity * (uint)sizeof(T)); } else { _storage = 0; } diff --git a/common/config-file.cpp b/common/config-file.cpp index ea3feff8ae..1ebd9b5701 100644 --- a/common/config-file.cpp +++ b/common/config-file.cpp @@ -36,7 +36,7 @@ namespace Common { * underscores. In particular, white space and "#", "=", "[", "]" * are not valid! */ -bool ConfigFile::isValidName(const Common::String &name) { +bool ConfigFile::isValidName(const String &name) { const char *p = name.c_str(); while (*p && (isalnum(static_cast<unsigned char>(*p)) || *p == '-' || *p == '_' || *p == '.')) p++; diff --git a/common/config-file.h b/common/config-file.h index d28ad34036..7bc5604b4c 100644 --- a/common/config-file.h +++ b/common/config-file.h @@ -93,7 +93,7 @@ public: * underscores. In particular, white space and "#", "=", "[", "]" * are not valid! */ - static bool isValidName(const Common::String &name); + static bool isValidName(const String &name); /** Reset everything stored in this config file. */ void clear(); diff --git a/common/config-manager.cpp b/common/config-manager.cpp index fbdb611f3c..c62dee8bea 100644 --- a/common/config-manager.cpp +++ b/common/config-manager.cpp @@ -38,11 +38,11 @@ namespace Common { DECLARE_SINGLETON(ConfigManager); -const char *ConfigManager::kApplicationDomain = "scummvm"; -const char *ConfigManager::kTransientDomain = "__TRANSIENT"; +char const *const ConfigManager::kApplicationDomain = "scummvm"; +char const *const ConfigManager::kTransientDomain = "__TRANSIENT"; #ifdef ENABLE_KEYMAPPER -const char *ConfigManager::kKeymapperDomain = "keymapper"; +char const *const ConfigManager::kKeymapperDomain = "keymapper"; #endif #pragma mark - @@ -112,7 +112,7 @@ void ConfigManager::loadConfigFile(const String &filename) { * Add a ready-made domain based on its name and contents * The domain name should not already exist in the ConfigManager. **/ -void ConfigManager::addDomain(const Common::String &domainName, const ConfigManager::Domain &domain) { +void ConfigManager::addDomain(const String &domainName, const ConfigManager::Domain &domain) { if (domainName.empty()) return; if (domainName == kApplicationDomain) { @@ -492,7 +492,7 @@ int ConfigManager::getInt(const String &key, const String &domName) const { bool ConfigManager::getBool(const String &key, const String &domName) const { String value(get(key, domName)); bool val; - if (Common::parseBool(value, val)) + if (parseBool(value, val)) return val; error("ConfigManager::getBool(%s,%s): '%s' is not a valid bool", @@ -696,4 +696,3 @@ bool ConfigManager::Domain::hasKVComment(const String &key) const { } } // End of namespace Common - diff --git a/common/config-manager.h b/common/config-manager.h index 78a62b9808..02d4ec3438 100644 --- a/common/config-manager.h +++ b/common/config-manager.h @@ -64,14 +64,14 @@ public: typedef HashMap<String, Domain, IgnoreCase_Hash, IgnoreCase_EqualTo> DomainMap; /** The name of the application domain (normally 'scummvm'). */ - static const char *kApplicationDomain; + static char const *const kApplicationDomain; /** The transient (pseudo) domain. */ - static const char *kTransientDomain; + static char const *const kTransientDomain; #ifdef ENABLE_KEYMAPPER /** The name of keymapper domain used to store the key maps */ - static const char *kKeymapperDomain; + static char const *const kKeymapperDomain; #endif void loadDefaultConfigFile(); @@ -153,7 +153,7 @@ private: ConfigManager(); void loadFromStream(SeekableReadStream &stream); - void addDomain(const Common::String &domainName, const Domain &domain); + void addDomain(const String &domainName, const Domain &domain); void writeDomain(WriteStream &stream, const String &name, const Domain &domain); void renameDomain(const String &oldName, const String &newName, DomainMap &map); diff --git a/common/dcl.cpp b/common/dcl.cpp index b75f7f3fa6..1879be992d 100644 --- a/common/dcl.cpp +++ b/common/dcl.cpp @@ -30,7 +30,7 @@ namespace Common { class DecompressorDCL { public: - bool unpack(Common::ReadStream *src, byte *dest, uint32 nPacked, uint32 nUnpacked); + bool unpack(ReadStream *src, byte *dest, uint32 nPacked, uint32 nUnpacked); protected: /** @@ -41,7 +41,7 @@ protected: * @param nUnpacket size of unpacked data * @return 0 on success, non-zero on error */ - void init(Common::ReadStream *src, byte *dest, uint32 nPacked, uint32 nUnpacked); + void init(ReadStream *src, byte *dest, uint32 nPacked, uint32 nUnpacked); /** * Get a number of bits from _src stream, starting with the least @@ -73,12 +73,11 @@ protected: uint32 _szUnpacked; ///< size of the decompressed data uint32 _dwRead; ///< number of bytes read from _src uint32 _dwWrote; ///< number of bytes written to _dest - Common::ReadStream *_src; + ReadStream *_src; byte *_dest; }; -void DecompressorDCL::init(Common::ReadStream *src, byte *dest, uint32 nPacked, - uint32 nUnpacked) { +void DecompressorDCL::init(ReadStream *src, byte *dest, uint32 nPacked, uint32 nUnpacked) { _src = src; _dest = dest; _szPacked = nPacked; @@ -333,7 +332,7 @@ int DecompressorDCL::huffman_lookup(const int *tree) { #define DCL_BINARY_MODE 0 #define DCL_ASCII_MODE 1 -bool DecompressorDCL::unpack(Common::ReadStream *src, byte *dest, uint32 nPacked, uint32 nUnpacked) { +bool DecompressorDCL::unpack(ReadStream *src, byte *dest, uint32 nPacked, uint32 nUnpacked) { init(src, dest, nPacked, nUnpacked); int value; diff --git a/common/dcl.h b/common/dcl.h index 12c4e12772..78ffa631ed 100644 --- a/common/dcl.h +++ b/common/dcl.h @@ -52,4 +52,3 @@ SeekableReadStream *decompressDCL(ReadStream *src, uint32 packedSize, uint32 unp } // End of namespace Common #endif - diff --git a/common/events.h b/common/events.h index 371080c1b2..f5ace7481b 100644 --- a/common/events.h +++ b/common/events.h @@ -97,7 +97,7 @@ struct Event { * Virtual screen coordinates means: the coordinate system of the * screen area as defined by the most recent call to initSize(). */ - Common::Point mouse; + Point mouse; Event() : type(EVENT_INVALID), synthetic(false) {} }; @@ -139,13 +139,13 @@ public: */ class ArtificialEventSource : public EventSource { protected: - Common::Queue<Common::Event> _artificialEventQueue; + Queue<Event> _artificialEventQueue; public: - void addEvent(const Common::Event &ev) { + void addEvent(const Event &ev) { _artificialEventQueue.push(ev); } - bool pollEvent(Common::Event &ev) { + bool pollEvent(Event &ev) { if (!_artificialEventQueue.empty()) { ev = _artificialEventQueue.pop(); return true; @@ -184,6 +184,14 @@ public: * false otherwise. */ virtual bool notifyEvent(const Event &event) = 0; + + /** + * Notifies the observer of pollEvent() query. + * + * @return true if the event should not be passed to other observers, + * false otherwise. + */ + virtual bool notifyPoll() { return false; } }; /** @@ -255,8 +263,11 @@ public: /** * Registers a new EventObserver with the Dispatcher. + * + * @param listenPools if set, then all pollEvent() calls are passed to observer + * currently it is used by keyMapper */ - void registerObserver(EventObserver *obs, uint priority, bool autoFree); + void registerObserver(EventObserver *obs, uint priority, bool autoFree, bool listenPolls = false); /** * Unregisters a EventObserver. @@ -275,16 +286,18 @@ private: EventSource *source; }; - Common::List<SourceEntry> _sources; + List<SourceEntry> _sources; struct ObserverEntry : public Entry { uint priority; EventObserver *observer; + bool poll; }; - Common::List<ObserverEntry> _observers; + List<ObserverEntry> _observers; void dispatchEvent(const Event &event); + void dispatchPoll(); }; class Keymapper; @@ -315,15 +328,15 @@ public: * @param event point to an Event struct, which will be filled with the event data. * @return true if an event was retrieved. */ - virtual bool pollEvent(Common::Event &event) = 0; + virtual bool pollEvent(Event &event) = 0; /** * Pushes a "fake" event into the event queue */ - virtual void pushEvent(const Common::Event &event) = 0; + virtual void pushEvent(const Event &event) = 0; /** Return the current mouse position */ - virtual Common::Point getMousePos() const = 0; + virtual Point getMousePos() const = 0; /** * Return a bitmask with the button states: @@ -362,7 +375,7 @@ public: // TODO: Consider removing OSystem::getScreenChangeID and // replacing it by a generic getScreenChangeID method here #ifdef ENABLE_KEYMAPPER - virtual Common::Keymapper *getKeymapper() = 0; + virtual Keymapper *getKeymapper() = 0; #endif enum { @@ -370,7 +383,12 @@ public: * Priority of the event manager, for now it's lowest since it eats * *all* events, we might to change that in the future though. */ - kEventManPriority = 0 + kEventManPriority = 0, + /** + * Priority of the event recorder. It has to go after event manager + * in order to record events generated by it + */ + kEventRecorderPriority = 1 }; /** diff --git a/common/file.cpp b/common/file.cpp index 381bf12ecf..12d73c9973 100644 --- a/common/file.cpp +++ b/common/file.cpp @@ -72,7 +72,7 @@ bool File::open(const FSNode &node) { return open(stream, node.getPath()); } -bool File::open(SeekableReadStream *stream, const Common::String &name) { +bool File::open(SeekableReadStream *stream, const String &name) { assert(!_handle); if (stream) { diff --git a/common/file.h b/common/file.h index 86c67c077c..b6319dfc3c 100644 --- a/common/file.h +++ b/common/file.h @@ -97,7 +97,7 @@ public: * @param name a string describing the 'file' corresponding to stream * @return true if stream was non-zero, false otherwise */ - virtual bool open(SeekableReadStream *stream, const Common::String &name); + virtual bool open(SeekableReadStream *stream, const String &name); /** * Close the file, if open. diff --git a/common/fs.cpp b/common/fs.cpp index 3dc8c289aa..8aa1115f9d 100644 --- a/common/fs.cpp +++ b/common/fs.cpp @@ -33,7 +33,7 @@ FSNode::FSNode(AbstractFSNode *realNode) : _realNode(realNode) { } -FSNode::FSNode(const Common::String &p) { +FSNode::FSNode(const String &p) { assert(g_system); FilesystemFactory *factory = g_system->getFilesystemFactory(); AbstractFSNode *tmp = 0; @@ -42,7 +42,7 @@ FSNode::FSNode(const Common::String &p) { tmp = factory->makeCurrentDirectoryFileNode(); else tmp = factory->makeFileNodePath(p); - _realNode = Common::SharedPtr<AbstractFSNode>(tmp); + _realNode = SharedPtr<AbstractFSNode>(tmp); } bool FSNode::operator<(const FSNode& node) const { @@ -59,7 +59,7 @@ bool FSNode::exists() const { return _realNode && _realNode->exists(); } -FSNode FSNode::getChild(const Common::String &n) const { +FSNode FSNode::getChild(const String &n) const { // If this node is invalid or not a directory, return an invalid node if (_realNode == 0 || !_realNode->isDirectory()) return FSNode(); @@ -85,12 +85,12 @@ bool FSNode::getChildren(FSList &fslist, ListMode mode, bool hidden) const { return true; } -Common::String FSNode::getDisplayName() const { +String FSNode::getDisplayName() const { assert(_realNode); return _realNode->getDisplayName(); } -Common::String FSNode::getName() const { +String FSNode::getName() const { assert(_realNode); return _realNode->getName(); } @@ -107,7 +107,7 @@ FSNode FSNode::getParent() const { } } -Common::String FSNode::getPath() const { +String FSNode::getPath() const { assert(_realNode); return _realNode->getPath(); } @@ -124,7 +124,7 @@ bool FSNode::isWritable() const { return _realNode && _realNode->isWritable(); } -Common::SeekableReadStream *FSNode::createReadStream() const { +SeekableReadStream *FSNode::createReadStream() const { if (_realNode == 0) return 0; @@ -139,7 +139,7 @@ Common::SeekableReadStream *FSNode::createReadStream() const { return _realNode->createReadStream(); } -Common::WriteStream *FSNode::createWriteStream() const { +WriteStream *FSNode::createWriteStream() const { if (_realNode == 0) return 0; diff --git a/common/func.h b/common/func.h index e09ab1a438..db57d73668 100644 --- a/common/func.h +++ b/common/func.h @@ -424,7 +424,7 @@ private: * are interesting for that matter. */ template<class Arg, class Res> -struct Functor1 : public Common::UnaryFunction<Arg, Res> { +struct Functor1 : public UnaryFunction<Arg, Res> { virtual ~Functor1() {} virtual bool isValid() const = 0; @@ -460,7 +460,7 @@ private: * @see Functor1 */ template<class Arg1, class Arg2, class Res> -struct Functor2 : public Common::BinaryFunction<Arg1, Arg2, Res> { +struct Functor2 : public BinaryFunction<Arg1, Arg2, Res> { virtual ~Functor2() {} virtual bool isValid() const = 0; @@ -538,4 +538,3 @@ GENERATE_TRIVIAL_HASH_FUNCTOR(unsigned long); } // End of namespace Common #endif - diff --git a/common/huffman.h b/common/huffman.h index 9a8b712c23..4175d0d309 100644 --- a/common/huffman.h +++ b/common/huffman.h @@ -66,9 +66,9 @@ private: Symbol(uint32 c, uint32 s); }; - typedef Common::List<Symbol> CodeList; - typedef Common::Array<CodeList> CodeLists; - typedef Common::Array<Symbol *> SymbolList; + typedef List<Symbol> CodeList; + typedef Array<CodeList> CodeLists; + typedef Array<Symbol*> SymbolList; /** Lists of codes and their symbols, sorted by code length. */ CodeLists _codes; diff --git a/common/iff_container.cpp b/common/iff_container.cpp index 02b445ae05..7bcbf86e0f 100644 --- a/common/iff_container.cpp +++ b/common/iff_container.cpp @@ -25,7 +25,7 @@ namespace Common { -IFFParser::IFFParser(Common::ReadStream *stream, bool disposeStream) : _stream(stream), _disposeStream(disposeStream) { +IFFParser::IFFParser(ReadStream *stream, bool disposeStream) : _stream(stream), _disposeStream(disposeStream) { setInputStream(stream); } @@ -36,7 +36,7 @@ IFFParser::~IFFParser() { _stream = 0; } -void IFFParser::setInputStream(Common::ReadStream *stream) { +void IFFParser::setInputStream(ReadStream *stream) { assert(stream); _formChunk.setInputStream(stream); _chunk.setInputStream(stream); @@ -63,7 +63,7 @@ void IFFParser::parse(IFFCallback &callback) { _chunk.readHeader(); // invoke the callback - Common::SubReadStream stream(&_chunk, _chunk.size); + SubReadStream stream(&_chunk, _chunk.size); IFFChunk chunk(_chunk.id, _chunk.size, &stream); stop = callback(chunk); diff --git a/common/iff_container.h b/common/iff_container.h index 1b12ef70e5..104ecf0f36 100644 --- a/common/iff_container.h +++ b/common/iff_container.h @@ -146,11 +146,11 @@ page 376) */ * Client code must *not* deallocate _stream when done. */ struct IFFChunk { - Common::IFF_ID _type; - uint32 _size; - Common::ReadStream *_stream; + IFF_ID _type; + uint32 _size; + ReadStream *_stream; - IFFChunk(Common::IFF_ID type, uint32 size, Common::ReadStream *stream) : _type(type), _size(size), _stream(stream) { + IFFChunk(IFF_ID type, uint32 size, ReadStream *stream) : _type(type), _size(size), _stream(stream) { assert(_stream); } }; @@ -163,17 +163,17 @@ class IFFParser { /** * This private class implements IFF chunk navigation. */ - class IFFChunkNav : public Common::ReadStream { + class IFFChunkNav : public ReadStream { protected: - Common::ReadStream *_input; + ReadStream *_input; uint32 _bytesRead; public: - Common::IFF_ID id; + IFF_ID id; uint32 size; IFFChunkNav() : _input(0) { } - void setInputStream(Common::ReadStream *input) { + void setInputStream(ReadStream *input) { _input = input; size = _bytesRead = 0; } @@ -199,7 +199,7 @@ class IFFParser { readByte(); } } - // Common::ReadStream implementation + // ReadStream implementation bool eos() const { return _input->eos(); } bool err() const { return _input->err(); } void clearErr() { _input->clearErr(); } @@ -215,21 +215,21 @@ protected: IFFChunkNav _chunk; ///< The current chunk. uint32 _formSize; - Common::IFF_ID _formType; + IFF_ID _formType; - Common::ReadStream *_stream; + ReadStream *_stream; bool _disposeStream; - void setInputStream(Common::ReadStream *stream); + void setInputStream(ReadStream *stream); public: - IFFParser(Common::ReadStream *stream, bool disposeStream = false); + IFFParser(ReadStream *stream, bool disposeStream = false); ~IFFParser(); /** * Callback type for the parser. */ - typedef Common::Functor1< IFFChunk&, bool > IFFCallback; + typedef Functor1< IFFChunk&, bool > IFFCallback; /** * Parse the IFF container, invoking the callback on each chunk encountered. diff --git a/common/keyboard.h b/common/keyboard.h index 74b8775a0f..bdd0a2d4af 100644 --- a/common/keyboard.h +++ b/common/keyboard.h @@ -291,7 +291,7 @@ struct KeyState { return f == (flags & ~(KBD_NUM|KBD_CAPS|KBD_SCRL)); } - bool operator ==(const KeyState &x) const { + bool operator==(const KeyState &x) const { return keycode == x.keycode && ascii == x.ascii && flags == x.flags; } }; diff --git a/common/localization.cpp b/common/localization.cpp new file mode 100644 index 0000000000..afd31b8d22 --- /dev/null +++ b/common/localization.cpp @@ -0,0 +1,66 @@ +/* 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. + */ + +#include "common/localization.h" +#include "common/translation.h" + +namespace Common { + +void getLanguageYesNo(Language id, KeyCode &keyYes, KeyCode &keyNo) { + // If all else fails, use English as fallback. + keyYes = KEYCODE_y; + keyNo = KEYCODE_n; + + switch (id) { + case Common::RU_RUS: + break; + case Common::PL_POL: + keyYes = Common::KEYCODE_t; + break; + case Common::HE_ISR: + keyYes = Common::KEYCODE_f; + break; + case Common::ES_ESP: + keyYes = Common::KEYCODE_s; + break; + case Common::IT_ITA: + keyYes = Common::KEYCODE_s; + break; + case Common::FR_FRA: + keyYes = Common::KEYCODE_o; + break; + case Common::DE_DEU: + keyYes = Common::KEYCODE_j; + break; + default: + break; + } +} + +void getLanguageYesNo(KeyCode &keyYes, KeyCode &keyNo) { +#ifdef USE_TRANSLATION + getLanguageYesNo(Common::parseLanguageFromLocale(TransMan.getCurrentLanguage().c_str()), keyYes, keyNo); +#else + getLanguageYesNo(Common::EN_ANY, keyYes, keyNo); +#endif +} + +} // End of namespace Common diff --git a/common/localization.h b/common/localization.h new file mode 100644 index 0000000000..3945cf5fab --- /dev/null +++ b/common/localization.h @@ -0,0 +1,52 @@ +/* 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_LOCALIZATION_H +#define COMMON_LOCALIZATION_H + +#include "common/util.h" +#include "common/keyboard.h" + +namespace Common { + +/** + * Get localized equivalents for Y/N buttons of the specified language. In + * case there is no specialized keys for the given language it will fall back + * to the English keys. + * + * @param id Language id + * @param keyYes Key code for yes + * @param keyYes Key code for no + */ +void getLanguageYesNo(Language id, KeyCode &keyYes, KeyCode &keyNo); + +/** + * Get localized equivalents for Y/N buttons of the current translation + * language of the ScummVM GUI. + * + * @param keyYes Key code for yes + * @param keyYes Key code for no + */ +void getLanguageYesNo(KeyCode &keyYes, KeyCode &keyNo); + +} // End of namespace Common + +#endif diff --git a/common/math.h b/common/math.h index ebe01fbaf5..f787b84fa6 100644 --- a/common/math.h +++ b/common/math.h @@ -26,6 +26,31 @@ #define COMMON_MATH_H #include "common/scummsys.h" +#ifdef _MSC_VER +// HACK: +// intrin.h on MSVC includes setjmp.h, which will fail compiling due to our +// forbidden symbol colde. Since we also can not assure that defining +// FORBIDDEN_SYMBOL_EXCEPTION_setjmp and FORBIDDEN_SYMBOL_EXCEPTION_longjmp +// will actually allow the symbols, since forbidden.h might be included +// earlier already we need to undefine them here... +#undef setjmp +#undef longjmp +#include <intrin.h> +// ...and redefine them here so no code can actually use it. +// This could be resolved by including intrin.h on MSVC in scummsys.h before +// the forbidden.h include. This might make sense, in case we use MSVC +// extensions like _BitScanReverse in more places. But for now this hack should +// be ok... +#ifndef FORBIDDEN_SYMBOL_EXCEPTION_setjmp +#undef setjmp +#define setjmp(a) FORBIDDEN_SYMBOL_REPLACEMENT +#endif + +#ifndef FORBIDDEN_SYMBOL_EXCEPTION_longjmp +#undef longjmp +#define longjmp(a,b) FORBIDDEN_SYMBOL_REPLACEMENT +#endif +#endif #ifndef M_SQRT1_2 #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ @@ -50,6 +75,28 @@ struct Complex { float re, im; }; +#if defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) +inline int intLog2(uint32 v) { + // This is a slightly optimized implementation of log2 for natural numbers + // targeting gcc. It also saves some binary size over our fallback + // implementation, since it does not need any table. + if (v == 0) + return -1; + else + // This is really "sizeof(unsigned int) * CHAR_BIT - 1" but using 8 + // instead of CHAR_BIT is sane enough and it saves us from including + // limits.h + return (sizeof(unsigned int) * 8 - 1) - __builtin_clz(v); +} +#elif defined(_MSC_VER) +inline int intLog2(uint32 v) { + unsigned long result = 0; + unsigned char nonZero = _BitScanReverse(&result, v); + // _BitScanReverse stores the position of the MSB set in case its result + // is non zero, thus we can just return it as is. + return nonZero ? result : -1; +} +#else // See http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogLookup static const char LogTable256[256] = { #define LT(n) n, n, n, n, n, n, n, n, n, n, n, n, n, n, n, n @@ -58,7 +105,7 @@ static const char LogTable256[256] = { LT(7), LT(7), LT(7), LT(7), LT(7), LT(7), LT(7), LT(7) }; -inline uint32 intLog2(uint32 v) { +inline int intLog2(uint32 v) { register uint32 t, tt; if ((tt = v >> 16)) @@ -66,6 +113,7 @@ inline uint32 intLog2(uint32 v) { else return (t = v >> 8) ? 8 + LogTable256[t] : LogTable256[v]; } +#endif inline float rad2deg(float rad) { return rad * 180.0 / M_PI; diff --git a/common/memorypool.cpp b/common/memorypool.cpp index 3a570ac50e..19adc54d00 100644 --- a/common/memorypool.cpp +++ b/common/memorypool.cpp @@ -180,4 +180,3 @@ void MemoryPool::freeUnusedPages() { } } // End of namespace Common - diff --git a/common/module.mk b/common/module.mk index 00caee86d1..b55c11637a 100644 --- a/common/module.mk +++ b/common/module.mk @@ -13,6 +13,7 @@ MODULE_OBJS := \ fs.o \ hashmap.o \ iff_container.o \ + localization.o \ macresman.o \ memorypool.o \ md5.o \ diff --git a/common/ptr.h b/common/ptr.h index fc272d3d41..2b0670caae 100644 --- a/common/ptr.h +++ b/common/ptr.h @@ -24,6 +24,7 @@ #include "common/scummsys.h" #include "common/noncopyable.h" +#include "common/types.h" namespace Common { @@ -185,12 +186,12 @@ public: } template<class T2> - bool operator==(const Common::SharedPtr<T2> &r) const { + bool operator==(const SharedPtr<T2> &r) const { return _pointer == r.get(); } template<class T2> - bool operator!=(const Common::SharedPtr<T2> &r) const { + bool operator!=(const SharedPtr<T2> &r) const { return _pointer != r.get(); } @@ -231,7 +232,6 @@ public: ReferenceType operator*() const { return *_pointer; } PointerType operator->() const { return _pointer; } - operator PointerType() const { return _pointer; } /** * Implicit conversion operator to bool for convenience, to make @@ -274,6 +274,41 @@ private: PointerType _pointer; }; + +template<typename T> +class DisposablePtr : NonCopyable { +public: + typedef T ValueType; + typedef T *PointerType; + typedef T &ReferenceType; + + explicit DisposablePtr(PointerType o, DisposeAfterUse::Flag dispose) : _pointer(o), _dispose(dispose) {} + + ~DisposablePtr() { + if (_dispose) delete _pointer; + } + + ReferenceType operator*() const { return *_pointer; } + PointerType operator->() const { return _pointer; } + + /** + * Implicit conversion operator to bool for convenience, to make + * checks like "if (scopedPtr) ..." possible. + */ + operator bool() const { return _pointer; } + + /** + * Returns the plain pointer value. + * + * @return the pointer the DisposablePtr manages + */ + PointerType get() const { return _pointer; } + +private: + PointerType _pointer; + DisposeAfterUse::Flag _dispose; +}; + } // End of namespace Common #endif diff --git a/common/quicktime.cpp b/common/quicktime.cpp index ee49b092a4..9ea8c229ea 100644 --- a/common/quicktime.cpp +++ b/common/quicktime.cpp @@ -8,19 +8,16 @@ * 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$ - * */ // @@ -51,7 +48,7 @@ QuickTimeParser::QuickTimeParser() { _fd = 0; _scaleFactorX = 1; _scaleFactorY = 1; - _resFork = new Common::MacResManager(); + _resFork = new MacResManager(); _disposeFileHandle = DisposeAfterUse::YES; initParseTable(); @@ -62,7 +59,7 @@ QuickTimeParser::~QuickTimeParser() { delete _resFork; } -bool QuickTimeParser::parseFile(const Common::String &filename) { +bool QuickTimeParser::parseFile(const String &filename) { if (!_resFork->open(filename) || !_resFork->hasDataFork()) return false; @@ -73,7 +70,7 @@ bool QuickTimeParser::parseFile(const Common::String &filename) { if (_resFork->hasResFork()) { // Search for a 'moov' resource - Common::MacResIDArray idArray = _resFork->getResIDArray(MKTAG('m', 'o', 'o', 'v')); + MacResIDArray idArray = _resFork->getResIDArray(MKTAG('m', 'o', 'o', 'v')); if (!idArray.empty()) _fd = _resFork->getResource(MKTAG('m', 'o', 'o', 'v'), idArray[0]); @@ -99,7 +96,7 @@ bool QuickTimeParser::parseFile(const Common::String &filename) { return true; } -bool QuickTimeParser::parseStream(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeFileHandle) { +bool QuickTimeParser::parseStream(SeekableReadStream *stream, DisposeAfterUse::Flag disposeFileHandle) { _fd = stream; _foundMOOV = false; _disposeFileHandle = disposeFileHandle; @@ -277,7 +274,7 @@ int QuickTimeParser::readCMOV(Atom atom) { // Uncompress the data unsigned long dstLen = uncompressedSize; - if (!Common::uncompress(uncompressedData, &dstLen, compressedData, compressedSize)) { + if (!uncompress(uncompressedData, &dstLen, compressedData, compressedSize)) { warning ("Could not uncompress cmov chunk"); free(compressedData); free(uncompressedData); @@ -285,8 +282,8 @@ int QuickTimeParser::readCMOV(Atom atom) { } // Load data into a new MemoryReadStream and assign _fd to be that - Common::SeekableReadStream *oldStream = _fd; - _fd = new Common::MemoryReadStream(uncompressedData, uncompressedSize, DisposeAfterUse::YES); + SeekableReadStream *oldStream = _fd; + _fd = new MemoryReadStream(uncompressedData, uncompressedSize, DisposeAfterUse::YES); // Read the contents of the uncompressed data Atom a = { MKTAG('m', 'o', 'o', 'v'), 0, uncompressedSize }; @@ -336,8 +333,8 @@ int QuickTimeParser::readMVHD(Atom atom) { uint32 yMod = _fd->readUint32BE(); _fd->skip(16); - _scaleFactorX = Common::Rational(0x10000, xMod); - _scaleFactorY = Common::Rational(0x10000, yMod); + _scaleFactorX = Rational(0x10000, xMod); + _scaleFactorY = Rational(0x10000, yMod); _scaleFactorX.debugPrint(1, "readMVHD(): scaleFactorX ="); _scaleFactorY.debugPrint(1, "readMVHD(): scaleFactorY ="); @@ -406,8 +403,8 @@ int QuickTimeParser::readTKHD(Atom atom) { uint32 yMod = _fd->readUint32BE(); _fd->skip(16); - track->scaleFactorX = Common::Rational(0x10000, xMod); - track->scaleFactorY = Common::Rational(0x10000, yMod); + track->scaleFactorX = Rational(0x10000, xMod); + track->scaleFactorY = Rational(0x10000, yMod); track->scaleFactorX.debugPrint(1, "readTKHD(): scaleFactorX ="); track->scaleFactorY.debugPrint(1, "readTKHD(): scaleFactorY ="); @@ -434,7 +431,7 @@ int QuickTimeParser::readELST(Atom atom) { for (uint32 i = 0; i < track->editCount; i++){ track->editList[i].trackDuration = _fd->readUint32BE(); track->editList[i].mediaTime = _fd->readSint32BE(); - track->editList[i].mediaRate = Common::Rational(_fd->readUint32BE(), 0x10000); + track->editList[i].mediaRate = Rational(_fd->readUint32BE(), 0x10000); debugN(3, "\tDuration = %d, Media Time = %d, ", track->editList[i].trackDuration, track->editList[i].mediaTime); track->editList[i].mediaRate.debugPrint(3, "Media Rate ="); } @@ -698,7 +695,7 @@ enum { kMP4DecSpecificDescTag = 5 }; -static int readMP4DescLength(Common::SeekableReadStream *stream) { +static int readMP4DescLength(SeekableReadStream *stream) { int length = 0; int count = 4; @@ -713,7 +710,7 @@ static int readMP4DescLength(Common::SeekableReadStream *stream) { return length; } -static void readMP4Desc(Common::SeekableReadStream *stream, byte &tag, int &length) { +static void readMP4Desc(SeekableReadStream *stream, byte &tag, int &length) { tag = stream->readByte(); length = readMP4DescLength(stream); } diff --git a/common/quicktime.h b/common/quicktime.h index cb2bed1202..e4c821e209 100644 --- a/common/quicktime.h +++ b/common/quicktime.h @@ -8,19 +8,16 @@ * 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$ - * */ // @@ -59,14 +56,14 @@ public: * Load a QuickTime file * @param filename the filename to load */ - bool parseFile(const Common::String &filename); + bool parseFile(const String &filename); /** * Load a QuickTime file from a SeekableReadStream * @param stream the stream to load * @param disposeFileHandle whether to delete the stream after use */ - bool parseStream(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeFileHandle = DisposeAfterUse::YES); + bool parseStream(SeekableReadStream *stream, DisposeAfterUse::Flag disposeFileHandle = DisposeAfterUse::YES); /** * Close a QuickTime file @@ -84,7 +81,7 @@ public: protected: // This is the file handle from which data is read from. It can be the actual file handle or a decompressed stream. - Common::SeekableReadStream *_fd; + SeekableReadStream *_fd; DisposeAfterUse::Flag _disposeFileHandle; @@ -113,7 +110,7 @@ protected: struct EditListEntry { uint32 trackDuration; int32 mediaTime; - Common::Rational mediaRate; + Rational mediaRate; }; struct Track; @@ -157,18 +154,18 @@ protected: uint16 height; CodecType codecType; - Common::Array<SampleDesc *> sampleDescs; + Array<SampleDesc*> sampleDescs; uint32 editCount; EditListEntry *editList; - Common::SeekableReadStream *extraData; + SeekableReadStream *extraData; uint32 frameCount; uint32 duration; uint32 startTime; - Common::Rational scaleFactorX; - Common::Rational scaleFactorY; + Rational scaleFactorX; + Rational scaleFactorY; byte objectTypeMP4; }; @@ -179,11 +176,11 @@ protected: bool _foundMOOV; uint32 _timeScale; uint32 _duration; - Common::Rational _scaleFactorX; - Common::Rational _scaleFactorY; - Common::Array<Track *> _tracks; + Rational _scaleFactorX; + Rational _scaleFactorY; + Array<Track*> _tracks; uint32 _beginOffset; - Common::MacResManager *_resFork; + MacResManager *_resFork; void initParseTable(); void init(); diff --git a/common/rational.cpp b/common/rational.cpp index cb287869bb..f5495da3a9 100644 --- a/common/rational.cpp +++ b/common/rational.cpp @@ -107,8 +107,8 @@ Rational &Rational::operator-=(const Rational &right) { Rational &Rational::operator*=(const Rational &right) { // Cross-cancel to avoid unnecessary overflow; // the result then is automatically normalized - const int gcd1 = Common::gcd(_num, right._denom); - const int gcd2 = Common::gcd(right._num, _denom); + const int gcd1 = gcd(_num, right._denom); + const int gcd2 = gcd(right._num, _denom); _num = (_num / gcd1) * (right._num / gcd2); _denom = (_denom / gcd2) * (right._denom / gcd1); diff --git a/common/serializer.h b/common/serializer.h index b874624d38..5b08a9a9fa 100644 --- a/common/serializer.h +++ b/common/serializer.h @@ -68,15 +68,15 @@ public: static const Version kLastVersion = 0xFFFFFFFF; protected: - Common::SeekableReadStream *_loadStream; - Common::WriteStream *_saveStream; + SeekableReadStream *_loadStream; + WriteStream *_saveStream; uint _bytesSynced; Version _version; public: - Serializer(Common::SeekableReadStream *in, Common::WriteStream *out) + Serializer(SeekableReadStream *in, WriteStream *out) : _loadStream(in), _saveStream(out), _bytesSynced(0), _version(0) { assert(in || out); } @@ -214,7 +214,7 @@ public: * Sync a C-string, by treating it as a zero-terminated byte sequence. * @todo Replace this method with a special Syncer class for Common::String */ - void syncString(Common::String &str, Version minVersion = 0, Version maxVersion = kLastVersion) { + void syncString(String &str, Version minVersion = 0, Version maxVersion = kLastVersion) { if (_version < minVersion || _version > maxVersion) return; // Ignore anything which is not supposed to be present in this save game version diff --git a/common/str.h b/common/str.h index 8e07b6233d..5039130707 100644 --- a/common/str.h +++ b/common/str.h @@ -219,14 +219,14 @@ public: * except that it stores the result in (variably sized) String * instead of a fixed size buffer. */ - static Common::String format(const char *fmt, ...) GCC_PRINTF(1,2); + static String format(const char *fmt, ...) GCC_PRINTF(1,2); /** * Print formatted data into a String object. Similar to vsprintf, * except that it stores the result in (variably sized) String * instead of a fixed size buffer. */ - static Common::String vformat(const char *fmt, va_list args); + static String vformat(const char *fmt, va_list args); public: typedef char * iterator; @@ -293,7 +293,7 @@ extern char *trim(char *t); * @param sep character used to separate path components * @return The last component of the path. */ -Common::String lastPathComponent(const Common::String &path, const char sep); +String lastPathComponent(const String &path, const char sep); /** * Normalize a given path to a canonical form. In particular: @@ -307,7 +307,7 @@ Common::String lastPathComponent(const Common::String &path, const char sep); * @param sep the separator token (usually '/' on Unix-style systems, or '\\' on Windows based stuff) * @return the normalized path */ -Common::String normalizePath(const Common::String &path, const char sep); +String normalizePath(const String &path, const char sep); /** diff --git a/common/stream.cpp b/common/stream.cpp index 60b40d0df2..30b3bca497 100644 --- a/common/stream.cpp +++ b/common/stream.cpp @@ -20,6 +20,7 @@ * */ +#include "common/ptr.h" #include "common/stream.h" #include "common/memstream.h" #include "common/substream.h" @@ -258,8 +259,7 @@ namespace { */ class BufferedReadStream : virtual public ReadStream { protected: - ReadStream *_parentStream; - DisposeAfterUse::Flag _disposeParentStream; + DisposablePtr<ReadStream> _parentStream; byte *_buf; uint32 _pos; bool _eos; // end of stream @@ -278,8 +278,7 @@ public: }; BufferedReadStream::BufferedReadStream(ReadStream *parentStream, uint32 bufSize, DisposeAfterUse::Flag disposeParentStream) - : _parentStream(parentStream), - _disposeParentStream(disposeParentStream), + : _parentStream(parentStream, disposeParentStream), _pos(0), _eos(false), _bufSize(0), @@ -291,8 +290,6 @@ BufferedReadStream::BufferedReadStream(ReadStream *parentStream, uint32 bufSize, } BufferedReadStream::~BufferedReadStream() { - if (_disposeParentStream) - delete _parentStream; delete[] _buf; } diff --git a/common/substream.h b/common/substream.h index f4f79ff02f..7e67389da1 100644 --- a/common/substream.h +++ b/common/substream.h @@ -23,6 +23,7 @@ #ifndef COMMON_SUBSTREAM_H #define COMMON_SUBSTREAM_H +#include "common/ptr.h" #include "common/stream.h" #include "common/types.h" @@ -38,24 +39,18 @@ namespace Common { */ class SubReadStream : virtual public ReadStream { protected: - ReadStream *_parentStream; - DisposeAfterUse::Flag _disposeParentStream; + DisposablePtr<ReadStream> _parentStream; uint32 _pos; uint32 _end; bool _eos; public: SubReadStream(ReadStream *parentStream, uint32 end, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO) - : _parentStream(parentStream), - _disposeParentStream(disposeParentStream), + : _parentStream(parentStream, disposeParentStream), _pos(0), _end(end), _eos(false) { assert(parentStream); } - ~SubReadStream() { - if (_disposeParentStream) - delete _parentStream; - } virtual bool eos() const { return _eos | _parentStream->eos(); } virtual bool err() const { return _parentStream->err(); } diff --git a/common/system.cpp b/common/system.cpp index 8d5bfd39cd..59210544ab 100644 --- a/common/system.cpp +++ b/common/system.cpp @@ -28,6 +28,7 @@ #include "common/savefile.h" #include "common/str.h" #include "common/taskbar.h" +#include "common/updates.h" #include "common/textconsole.h" #include "backends/audiocd/default/default-audiocd.h" @@ -44,6 +45,9 @@ OSystem::OSystem() { #if defined(USE_TASKBAR) _taskbarManager = 0; #endif +#if defined(USE_UPDATES) + _updateManager = 0; +#endif _fsFactory = 0; } @@ -62,6 +66,11 @@ OSystem::~OSystem() { _taskbarManager = 0; #endif +#if defined(USE_UPDATES) + delete _updateManager; + _updateManager = 0; +#endif + delete _savefileManager; _savefileManager = 0; diff --git a/common/system.h b/common/system.h index 9b833c5b1a..413fe326a7 100644 --- a/common/system.h +++ b/common/system.h @@ -45,6 +45,9 @@ class String; #if defined(USE_TASKBAR) class TaskbarManager; #endif +#if defined(USE_UPDATES) +class UpdateManager; +#endif class TimerManager; class SeekableReadStream; class WriteStream; @@ -161,6 +164,15 @@ protected: Common::TaskbarManager *_taskbarManager; #endif +#if defined(USE_UPDATES) + /** + * No default value is provided for _updateManager by OSystem. + * + * @note _updateManager is deleted by the OSystem destructor. + */ + Common::UpdateManager *_updateManager; +#endif + /** * No default value is provided for _fsFactory by OSystem. * @@ -391,6 +403,11 @@ public: * factor 2x, too, just like the game graphics. But if it has a * cursorTargetScale of 2, then it shouldn't be scaled again by * the game graphics scaler. + * + * On a note for OSystem users here. We do not require our graphics + * to be thread safe and in fact most/all backends using OpenGL are + * not. So do *not* try to call any of these functions from a timer + * and/or audio callback (like readBuffer of AudioStreams). */ //@{ @@ -1071,6 +1088,18 @@ public: } #endif +#if defined(USE_UPDATES) + /** + * Returns the UpdateManager, used to handle auto-updating, + * and updating of ScummVM in general. + * + * @return the UpdateManager for the current architecture + */ + virtual Common::UpdateManager *getUpdateManager() { + return _updateManager; + } +#endif + /** * Returns the FilesystemFactory object, depending on the current architecture. * diff --git a/common/taskbar.h b/common/taskbar.h index 023227e5e0..ba99d4e487 100644 --- a/common/taskbar.h +++ b/common/taskbar.h @@ -18,8 +18,6 @@ * 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_TASKBAR_MANAGER_H @@ -124,6 +122,18 @@ public: */ virtual void addRecent(const String &name, const String &description) {} + /** + * Notifies the user an error occured through the taskbar icon + * + * This will for example show the taskbar icon as red (using progress of 100% and an error state) + * on Windows, and set the launcher icon in the urgent state on Unity + */ + virtual void notifyError() {} + + /** + * Clears the error notification + */ + virtual void clearError() {} }; } // End of namespace Common diff --git a/common/timer.h b/common/timer.h index 40438f078c..3db32df76a 100644 --- a/common/timer.h +++ b/common/timer.h @@ -23,6 +23,7 @@ #define COMMON_TIMER_H #include "common/scummsys.h" +#include "common/str.h" #include "common/noncopyable.h" namespace Common { @@ -43,9 +44,10 @@ public: * @param proc the callback * @param interval the interval in which the timer shall be invoked (in microseconds) * @param refCon an arbitrary void pointer; will be passed to the timer callback + * @param id unique string id of the installed timer. Used by the event recorder * @return true if the timer was installed successfully, false otherwise */ - virtual bool installTimerProc(TimerProc proc, int32 interval, void *refCon) = 0; + virtual bool installTimerProc(TimerProc proc, int32 interval, void *refCon, const Common::String &id) = 0; /** * Remove the given timer callback. It will not be invoked anymore, diff --git a/common/tokenizer.cpp b/common/tokenizer.cpp index 395ff0767a..46ba7a8d8b 100644 --- a/common/tokenizer.cpp +++ b/common/tokenizer.cpp @@ -53,4 +53,3 @@ String StringTokenizer::nextToken() { } } // End of namespace Common - diff --git a/common/translation.cpp b/common/translation.cpp index 5c8a04352d..3570e8c5ae 100644 --- a/common/translation.cpp +++ b/common/translation.cpp @@ -19,7 +19,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#ifdef WIN32 +#if defined(WIN32) #define WIN32_LEAN_AND_MEAN #include <windows.h> // winnt.h defines ARRAYSIZE, but we want our own one... - this is needed before including util.h diff --git a/common/unarj.cpp b/common/unarj.cpp index f45dddaa38..cccc330bb5 100644 --- a/common/unarj.cpp +++ b/common/unarj.cpp @@ -293,8 +293,8 @@ ArjHeader *readHeader(SeekableReadStream &stream) { return NULL; } - Common::strlcpy(header.filename, (const char *)&headData[header.firstHdrSize], ARJ_FILENAME_MAX); - Common::strlcpy(header.comment, (const char *)&headData[header.firstHdrSize + strlen(header.filename) + 1], ARJ_COMMENT_MAX); + strlcpy(header.filename, (const char *)&headData[header.firstHdrSize], ARJ_FILENAME_MAX); + strlcpy(header.comment, (const char *)&headData[header.firstHdrSize + strlen(header.filename) + 1], ARJ_COMMENT_MAX); // Process extended headers, if any uint16 extHeaderSize; @@ -692,15 +692,15 @@ void ArjDecoder::decode_f(int32 origsize) { typedef HashMap<String, ArjHeader*, IgnoreCase_Hash, IgnoreCase_EqualTo> ArjHeadersMap; -class ArjArchive : public Common::Archive { +class ArjArchive : public Archive { ArjHeadersMap _headers; - Common::String _arjFilename; + String _arjFilename; public: ArjArchive(const String &name); virtual ~ArjArchive(); - // Common::Archive implementation + // Archive implementation virtual bool hasFile(const String &name); virtual int listMembers(ArchiveMemberList &list); virtual ArchiveMemberPtr getMember(const String &name); @@ -708,7 +708,7 @@ public: }; ArjArchive::ArjArchive(const String &filename) : _arjFilename(filename) { - Common::File arjFile; + File arjFile; if (!arjFile.open(_arjFilename)) { warning("ArjArchive::ArjArchive(): Could not find the archive file"); @@ -775,7 +775,7 @@ SeekableReadStream *ArjArchive::createReadStreamForMember(const String &name) co ArjHeader *hdr = _headers[name]; - Common::File archiveFile; + File archiveFile; archiveFile.open(_arjFilename); archiveFile.seek(hdr->pos, SEEK_SET); @@ -794,8 +794,8 @@ SeekableReadStream *ArjArchive::createReadStreamForMember(const String &name) co // If reading from archiveFile directly is too slow to be usable, // maybe the filesystem code should instead wrap its files // in a BufferedReadStream. - decoder->_compressed = Common::wrapBufferedReadStream(&archiveFile, 4096, DisposeAfterUse::NO); - decoder->_outstream = new Common::MemoryWriteStream(uncompressedData, hdr->origSize); + decoder->_compressed = wrapBufferedReadStream(&archiveFile, 4096, DisposeAfterUse::NO); + decoder->_outstream = new MemoryWriteStream(uncompressedData, hdr->origSize); if (hdr->method == 1 || hdr->method == 2 || hdr->method == 3) decoder->decode(hdr->origSize); @@ -805,7 +805,7 @@ SeekableReadStream *ArjArchive::createReadStreamForMember(const String &name) co delete decoder; } - return new Common::MemoryReadStream(uncompressedData, hdr->origSize, DisposeAfterUse::YES); + return new MemoryReadStream(uncompressedData, hdr->origSize, DisposeAfterUse::YES); } Archive *makeArjArchive(const String &name) { diff --git a/common/unzip.cpp b/common/unzip.cpp index 91f352f40a..8650c91866 100644 --- a/common/unzip.cpp +++ b/common/unzip.cpp @@ -1458,11 +1458,11 @@ ZipArchive::~ZipArchive() { unzClose(_zipFile); } -bool ZipArchive::hasFile(const Common::String &name) { +bool ZipArchive::hasFile(const String &name) { return (unzLocateFile(_zipFile, name.c_str(), 2) == UNZ_OK); } -int ZipArchive::listMembers(Common::ArchiveMemberList &list) { +int ZipArchive::listMembers(ArchiveMemberList &list) { int matches = 0; int err = unzGoToFirstFile(_zipFile); @@ -1488,7 +1488,7 @@ ArchiveMemberPtr ZipArchive::getMember(const String &name) { return ArchiveMemberPtr(new GenericArchiveMember(name, this)); } -Common::SeekableReadStream *ZipArchive::createReadStreamForMember(const Common::String &name) const { +SeekableReadStream *ZipArchive::createReadStreamForMember(const String &name) const { if (unzLocateFile(_zipFile, name.c_str(), 2) != UNZ_OK) return 0; @@ -1512,7 +1512,7 @@ Common::SeekableReadStream *ZipArchive::createReadStreamForMember(const Common:: return 0; } - return new Common::MemoryReadStream(buffer, fileInfo.uncompressed_size, DisposeAfterUse::YES); + return new MemoryReadStream(buffer, fileInfo.uncompressed_size, DisposeAfterUse::YES); // FIXME: instead of reading all into a memory stream, we could // instead create a new ZipStream class. But then we have to be diff --git a/common/updates.h b/common/updates.h new file mode 100644 index 0000000000..1e0babdf6d --- /dev/null +++ b/common/updates.h @@ -0,0 +1,102 @@ +/* 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 BACKENDS_UPDATES_ABSTRACT_H +#define BACKENDS_UPDATES_ABSTRACT_H + +#if defined(USE_UPDATES) + +namespace Common { + +/** + * The UpdateManager allows configuring of the automatic update checking + * for systems that support it: + * - using Sparkle on MacOSX + * - using WinSparkle on Windows + * + * Most of the update checking is completely automated and this class only + * gives access to basic settings. It is mostly used by the GUI to set + * widgets state on the update page and for manually checking for updates + * + */ +class UpdateManager { +public: + enum UpdateState { + kUpdateStateDisabled = 0, + kUpdateStateEnabled = 1, + kUpdateStateNotSupported = 2 + }; + + enum UpdateInterval { + kUpdateIntervalNotSupported = 0, + kUpdateIntervalOneDay = 86400, + kUpdateIntervalOneWeek = 604800, + kUpdateIntervalOneMonth = 2628000 // average seconds per month (60*60*24*365)/12 + }; + + UpdateManager() {} + virtual ~UpdateManager() {} + + /** + * Checks manually if an update is available, showing progress UI to the user. + * + * By default, update checks are done silently on start. + * This allows to manually start an update check. + */ + virtual void checkForUpdates() {} + + /** + * Sets the automatic update checking state + * + * @param state The state. + */ + virtual void setAutomaticallyChecksForUpdates(UpdateState state) {} + + /** + * Gets the automatic update checking state + * + * @return kUpdateStateDisabled if automatic update checking is disabled, + * kUpdateStateEnabled if automatic update checking is enabled, + * kUpdateStateNotSupported if automatic update checking is not available + */ + virtual UpdateState getAutomaticallyChecksForUpdates() { return kUpdateStateNotSupported; } + + /** + * Sets the update checking interval. + * + * @param interval The interval. + */ + virtual void setUpdateCheckInterval(UpdateInterval interval) {} + + /** + * Gets the update check interval. + * + * @return the update check interval. + */ + virtual UpdateInterval getUpdateCheckInterval() { return kUpdateIntervalNotSupported; } +}; + +} // End of namespace Common + +#endif + +#endif // BACKENDS_UPDATES_ABSTRACT_H diff --git a/common/util.cpp b/common/util.cpp index a7ec1a9de7..699950dac3 100644 --- a/common/util.cpp +++ b/common/util.cpp @@ -82,7 +82,7 @@ void hexdump(const byte *data, int len, int bytesPerLine, int startOffset) { #pragma mark - -bool parseBool(const Common::String &val, bool &valAsBool) { +bool parseBool(const String &val, bool &valAsBool) { if (val.equalsIgnoreCase("true") || val.equalsIgnoreCase("yes") || val.equals("1")) { @@ -104,29 +104,29 @@ bool parseBool(const Common::String &val, bool &valAsBool) { const LanguageDescription g_languages[] = { - { "zh-cn"/*, "zh_CN"*/, "Chinese (China)", ZH_CNA }, - { "zh"/*, "zh_TW"*/, "Chinese (Taiwan)", ZH_TWN }, - { "cz"/*, "cs_CZ"*/, "Czech", CZ_CZE }, - { "nl"/*, "nl_NL"*/, "Dutch", NL_NLD }, - { "en"/*, "en"*/, "English", EN_ANY }, // Generic English (when only one game version exist) - { "gb"/*, "en_GB"*/, "English (GB)", EN_GRB }, - { "us"/*, "en_US"*/, "English (US)", EN_USA }, - { "fr"/*, "fr_FR"*/, "French", FR_FRA }, - { "de"/*, "de_DE"*/, "German", DE_DEU }, - { "gr"/*, "el_GR"*/, "Greek", GR_GRE }, - { "he"/*, "he_IL"*/, "Hebrew", HE_ISR }, - { "hb"/*, "he_IL"*/, "Hebrew", HE_ISR }, // Deprecated - { "hu"/*, "hu_HU"*/, "Hungarian", HU_HUN }, - { "it"/*, "it_IT"*/, "Italian", IT_ITA }, - { "jp"/*, "ja_JP"*/, "Japanese", JA_JPN }, - { "kr"/*, "ko_KR"*/, "Korean", KO_KOR }, - { "nb"/*, "nb_NO"*/, "Norwegian Bokm\xE5l", NB_NOR }, // TODO Someone should verify the unix locale - { "pl"/*, "pl_PL"*/, "Polish", PL_POL }, - { "br"/*, "pt_BR"*/, "Portuguese", PT_BRA }, - { "ru"/*, "ru_RU"*/, "Russian", RU_RUS }, - { "es"/*, "es_ES"*/, "Spanish", ES_ESP }, - { "se"/*, "sv_SE"*/, "Swedish", SE_SWE }, - { 0/*, 0*/, 0, UNK_LANG } + { "zh-cn", "zh_CN", "Chinese (China)", ZH_CNA }, + { "zh", "zh_TW", "Chinese (Taiwan)", ZH_TWN }, + { "cz", "cs_CZ", "Czech", CZ_CZE }, + { "nl", "nl_NL", "Dutch", NL_NLD }, + { "en", "en", "English", EN_ANY }, // Generic English (when only one game version exist) + { "gb", "en_GB", "English (GB)", EN_GRB }, + { "us", "en_US", "English (US)", EN_USA }, + { "fr", "fr_FR", "French", FR_FRA }, + { "de", "de_DE", "German", DE_DEU }, + { "gr", "el_GR", "Greek", GR_GRE }, + { "he", "he_IL", "Hebrew", HE_ISR }, + { "hb", "he_IL", "Hebrew", HE_ISR }, // Deprecated + { "hu", "hu_HU", "Hungarian", HU_HUN }, + { "it", "it_IT", "Italian", IT_ITA }, + { "jp", "ja_JP", "Japanese", JA_JPN }, + { "kr", "ko_KR", "Korean", KO_KOR }, + { "nb", "nb_NO", "Norwegian Bokm\xE5l", NB_NOR }, // TODO Someone should verify the unix locale + { "pl", "pl_PL", "Polish", PL_POL }, + { "br", "pt_BR", "Portuguese", PT_BRA }, + { "ru", "ru_RU", "Russian", RU_RUS }, + { "es", "es_ES", "Spanish", ES_ESP }, + { "se", "sv_SE", "Swedish", SE_SWE }, + { 0, 0, 0, UNK_LANG } }; Language parseLanguage(const String &str) { @@ -142,7 +142,7 @@ Language parseLanguage(const String &str) { return UNK_LANG; } -/*Language parseLanguageFromLocale(const char *locale) { +Language parseLanguageFromLocale(const char *locale) { if (!locale || !*locale) return UNK_LANG; @@ -153,7 +153,7 @@ Language parseLanguage(const String &str) { } return UNK_LANG; -}*/ +} const char *getLanguageCode(Language id) { const LanguageDescription *l = g_languages; @@ -164,14 +164,14 @@ const char *getLanguageCode(Language id) { return 0; } -/*const char *getLanguageLocale(Language id) { +const char *getLanguageLocale(Language id) { const LanguageDescription *l = g_languages; for (; l->code; ++l) { if (l->id == id) return l->unixLocale; } return 0; -}*/ +} const char *getLanguageDescription(Language id) { const LanguageDescription *l = g_languages; @@ -271,6 +271,7 @@ const char *getPlatformDescription(Platform id) { const RenderModeDescription g_renderModes[] = { + // I18N: Hercules is graphics card name { "hercGreen", _s("Hercules Green"), kRenderHercG }, { "hercAmber", _s("Hercules Amber"), kRenderHercA }, { "cga", "CGA", kRenderCGA }, @@ -402,4 +403,3 @@ void updateGameGUIOptions(const uint32 options, const String &langOption) { } } // End of namespace Common - diff --git a/common/util.h b/common/util.h index cd890c970f..bccb17c6da 100644 --- a/common/util.h +++ b/common/util.h @@ -58,6 +58,11 @@ template<typename T> inline void SWAP(T &a, T &b) { T tmp = a; a = b; b = tmp; } */ #define ARRAYSIZE(x) ((int)(sizeof(x) / sizeof(x[0]))) +/** + * Compute a pointer to one past the last element of an array. + */ +#define ARRAYEND(x) ((x) + ARRAYSIZE((x))) + /** * @def SCUMMVM_CURRENT_FUNCTION @@ -96,7 +101,7 @@ extern void hexdump(const byte * data, int len, int bytesPerLine = 16, int start * @param[out] valAsBool the parsing result * @return true if the string parsed correctly, false if an error occurred. */ -bool parseBool(const Common::String &val, bool &valAsBool); +bool parseBool(const String &val, bool &valAsBool); /** * List of game language. @@ -129,9 +134,9 @@ enum Language { struct LanguageDescription { const char *code; - //const char *unixLocale; + const char *unixLocale; const char *description; - Common::Language id; + Language id; }; extern const LanguageDescription g_languages[]; @@ -139,13 +144,11 @@ extern const LanguageDescription g_languages[]; /** Convert a string containing a language name into a Language enum value. */ extern Language parseLanguage(const String &str); +extern Language parseLanguageFromLocale(const char *locale); extern const char *getLanguageCode(Language id); +extern const char *getLanguageLocale(Language id); extern const char *getLanguageDescription(Language id); -// locale <-> Language conversion is disabled, since it is not used currently -/*extern const char *getLanguageLocale(Language id); -extern Language parseLanguageFromLocale(const char *locale);*/ - /** * List of game platforms. Specifying a platform for a target can be used to * give the game engines a hint for which platform the game data file are. @@ -182,7 +185,7 @@ struct PlatformDescription { const char *code2; const char *abbrev; const char *description; - Common::Platform id; + Platform id; }; extern const PlatformDescription g_platforms[]; @@ -211,7 +214,7 @@ enum RenderMode { struct RenderModeDescription { const char *code; const char *description; - Common::RenderMode id; + RenderMode id; }; extern const RenderModeDescription g_renderModes[]; diff --git a/common/winexe_pe.cpp b/common/winexe_pe.cpp index e5f6a24bcd..6c0f9c9962 100644 --- a/common/winexe_pe.cpp +++ b/common/winexe_pe.cpp @@ -133,7 +133,7 @@ void PEResources::parseResourceLevel(Section §ion, uint32 offset, int level) _exe->seek(section.offset + (value & 0x7fffffff)); // Read in the name, truncating from unicode to ascii - Common::String name; + String name; uint16 nameLength = _exe->readUint16LE(); while (nameLength--) name += (char)(_exe->readUint16LE() & 0xff); diff --git a/common/xmlparser.cpp b/common/xmlparser.cpp index 623619914a..f768e44382 100644 --- a/common/xmlparser.cpp +++ b/common/xmlparser.cpp @@ -81,7 +81,7 @@ void XMLParser::close() { _stream = 0; } -bool XMLParser::parserError(const Common::String &errStr) { +bool XMLParser::parserError(const String &errStr) { _state = kParserError; const int startPosition = _stream->pos(); diff --git a/common/xmlparser.h b/common/xmlparser.h index d75dc0e4a9..93433b7132 100644 --- a/common/xmlparser.h +++ b/common/xmlparser.h @@ -275,7 +275,7 @@ protected: * Parser error always returns "false" so we can pass the return value * directly and break down the parsing. */ - bool parserError(const Common::String &errStr); + bool parserError(const String &errStr); /** * Skips spaces/whitelines etc. diff --git a/common/zlib.cpp b/common/zlib.cpp index b047586af0..86c618830e 100644 --- a/common/zlib.cpp +++ b/common/zlib.cpp @@ -24,6 +24,7 @@ #define FORBIDDEN_SYMBOL_ALLOW_ALL #include "common/zlib.h" +#include "common/ptr.h" #include "common/util.h" #include "common/stream.h" @@ -53,7 +54,7 @@ bool uncompress(byte *dst, unsigned long *dstLen, const byte *src, unsigned long * other SeekableReadStream and will then provide on-the-fly decompression support. * Assumes the compressed data to be in gzip format. */ -class GZipReadStream : public Common::SeekableReadStream { +class GZipReadStream : public SeekableReadStream { protected: enum { BUFSIZE = 16384 // 1 << MAX_WBITS @@ -61,7 +62,7 @@ protected: byte _buf[BUFSIZE]; - Common::SeekableReadStream *_wrapped; + ScopedPtr<SeekableReadStream> _wrapped; z_stream _stream; int _zlibErr; uint32 _pos; @@ -70,13 +71,9 @@ protected: public: - GZipReadStream(Common::SeekableReadStream *w) : _wrapped(w) { + GZipReadStream(SeekableReadStream *w) : _wrapped(w), _stream() { assert(w != 0); - _stream.zalloc = Z_NULL; - _stream.zfree = Z_NULL; - _stream.opaque = Z_NULL; - // Verify file header is correct w->seek(0, SEEK_SET); uint16 header = w->readUint16BE(); @@ -111,7 +108,6 @@ public: ~GZipReadStream() { inflateEnd(&_stream); - delete _wrapped; } bool err() const { return (_zlibErr != Z_OK) && (_zlibErr != Z_STREAM_END); } @@ -201,14 +197,14 @@ public: * other WriteStream and will then provide on-the-fly compression support. * The compressed data is written in the gzip format. */ -class GZipWriteStream : public Common::WriteStream { +class GZipWriteStream : public WriteStream { protected: enum { BUFSIZE = 16384 // 1 << MAX_WBITS }; byte _buf[BUFSIZE]; - Common::WriteStream *_wrapped; + ScopedPtr<WriteStream> _wrapped; z_stream _stream; int _zlibErr; @@ -228,11 +224,8 @@ protected: } public: - GZipWriteStream(Common::WriteStream *w) : _wrapped(w) { + GZipWriteStream(WriteStream *w) : _wrapped(w), _stream() { assert(w != 0); - _stream.zalloc = Z_NULL; - _stream.zfree = Z_NULL; - _stream.opaque = Z_NULL; // Adding 16 to windowBits indicates to zlib that it is supposed to // write gzip headers. This feature was added in zlib 1.2.0.4, @@ -255,7 +248,6 @@ public: ~GZipWriteStream() { finalize(); deflateEnd(&_stream); - delete _wrapped; } bool err() const { @@ -308,7 +300,7 @@ public: #endif // USE_ZLIB -Common::SeekableReadStream *wrapCompressedReadStream(Common::SeekableReadStream *toBeWrapped) { +SeekableReadStream *wrapCompressedReadStream(SeekableReadStream *toBeWrapped) { #if defined(USE_ZLIB) if (toBeWrapped) { uint16 header = toBeWrapped->readUint16BE(); @@ -323,7 +315,7 @@ Common::SeekableReadStream *wrapCompressedReadStream(Common::SeekableReadStream return toBeWrapped; } -Common::WriteStream *wrapCompressedWriteStream(Common::WriteStream *toBeWrapped) { +WriteStream *wrapCompressedWriteStream(WriteStream *toBeWrapped) { #if defined(USE_ZLIB) if (toBeWrapped) return new GZipWriteStream(toBeWrapped); |