diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/EventDispatcher.cpp | 6 | ||||
-rw-r--r-- | common/EventMapper.cpp | 38 | ||||
-rw-r--r-- | common/events.h | 17 | ||||
-rw-r--r-- | common/macresman.cpp | 21 | ||||
-rw-r--r-- | common/macresman.h | 7 | ||||
-rw-r--r-- | common/stream.cpp | 2 | ||||
-rw-r--r-- | common/substream.h | 17 | ||||
-rw-r--r-- | common/translation.cpp | 5 |
8 files changed, 103 insertions, 10 deletions
diff --git a/common/EventDispatcher.cpp b/common/EventDispatcher.cpp index 4c7286bbb5..012a2dfce5 100644 --- a/common/EventDispatcher.cpp +++ b/common/EventDispatcher.cpp @@ -60,6 +60,12 @@ void EventDispatcher::dispatch() { } } } + + List<Event> delayedEvents = _mapper->getDelayedEvents(); + for (List<Event>::iterator k = delayedEvents.begin(); k != delayedEvents.end(); ++k) { + const Event delayedEvent = *k; + dispatchEvent(delayedEvent); + } } void EventDispatcher::registerMapper(EventMapper *mapper) { diff --git a/common/EventMapper.cpp b/common/EventMapper.cpp index 2808a7b5fd..47db61e472 100644 --- a/common/EventMapper.cpp +++ b/common/EventMapper.cpp @@ -22,6 +22,9 @@ #include "common/events.h" +#include "common/system.h" +#include "common/textconsole.h" + namespace Common { List<Event> DefaultEventMapper::mapEvent(const Event &ev, EventSource *source) { @@ -46,9 +49,44 @@ List<Event> DefaultEventMapper::mapEvent(const Event &ev, EventSource *source) { // if it didn't get mapped, just pass it through if (mappedEvent.type == EVENT_INVALID) mappedEvent = ev; + +#ifdef ENABLE_VKEYBD + // TODO: this check is not needed post-split + if (mappedEvent.type == EVENT_CUSTOM_BACKEND_HARDWARE) { + warning("EVENT_CUSTOM_BACKEND_HARDWARE was not mapped"); + return List<Event>(); + } +#endif + events.push_back(mappedEvent); return events; } +void DefaultEventMapper::addDelayedEvent(uint32 millis, Event ev) { + if (_delayedEvents.empty()) { + _delayedEffectiveTime = g_system->getMillis() + millis; + millis = 0; + } + DelayedEventsEntry entry = DelayedEventsEntry(millis, ev); + _delayedEvents.push(entry); +} + +List<Event> DefaultEventMapper::getDelayedEvents() { + List<Event> events; + + if (_delayedEvents.empty()) + return events; + + uint32 now = g_system->getMillis(); + + while (!_delayedEvents.empty() && now >= _delayedEffectiveTime) { + DelayedEventsEntry entry = _delayedEvents.pop(); + if (!_delayedEvents.empty()) + _delayedEffectiveTime += _delayedEvents.front().timerOffset; + events.push_back(entry.event); + } + return events; +} + } // namespace Common diff --git a/common/events.h b/common/events.h index 4efdd67b91..7366c51d36 100644 --- a/common/events.h +++ b/common/events.h @@ -79,6 +79,8 @@ enum EventType { // IMPORTANT NOTE: This is part of the WIP Keymapper. If you plan to use // this, please talk to tsoliman and/or LordHoto. EVENT_CUSTOM_BACKEND_ACTION = 18, + EVENT_CUSTOM_BACKEND_HARDWARE = 21, + EVENT_GUI_REMAP_COMPLETE_ACTION = 22, EVENT_KEYMAPPER_REMAP = 19 #endif #ifdef ENABLE_VKEYBD @@ -230,12 +232,27 @@ public: * Map an incoming event to one or more action events */ virtual List<Event> mapEvent(const Event &ev, EventSource *source) = 0; + + virtual List<Event> getDelayedEvents() = 0; }; class DefaultEventMapper : public EventMapper { public: + DefaultEventMapper() : _delayedEvents(), _delayedEffectiveTime(0) {} // EventMapper interface virtual List<Event> mapEvent(const Event &ev, EventSource *source); + virtual List<Event> getDelayedEvents(); +protected: + virtual void addDelayedEvent(uint32 millis, Event ev); + + struct DelayedEventsEntry { + const uint32 timerOffset; + const Event event; + DelayedEventsEntry(const uint32 offset, const Event ev) : timerOffset(offset), event(ev) { } + }; + + Queue<DelayedEventsEntry> _delayedEvents; + uint32 _delayedEffectiveTime; }; /** diff --git a/common/macresman.cpp b/common/macresman.cpp index 1317600cb7..14bdfa7080 100644 --- a/common/macresman.cpp +++ b/common/macresman.cpp @@ -238,6 +238,27 @@ bool MacResManager::open(FSNode path, String filename) { return false; } +bool MacResManager::exists(const String &filename) { + // Try the file name by itself + if (Common::File::exists(filename)) + return true; + + // Try the .rsrc extension + if (Common::File::exists(filename + ".rsrc")) + return true; + + // Check if we have a MacBinary file + Common::File tempFile; + if (tempFile.open(filename + ".bin") && isMacBinary(tempFile)) + return true; + + // Check if we have an AppleDouble file + if (tempFile.open("._" + filename) && tempFile.readUint32BE() == 0x00051607) + return true; + + return false; +} + bool MacResManager::loadFromAppleDouble(SeekableReadStream &stream) { if (stream.readUint32BE() != 0x00051607) // tag return false; diff --git a/common/macresman.h b/common/macresman.h index 4d86e46d11..6820106925 100644 --- a/common/macresman.h +++ b/common/macresman.h @@ -69,6 +69,13 @@ public: bool open(FSNode path, String filename); /** + * See if a Mac data/resource fork pair exists. + * @param filename The base file name of the file + * @return True if either a data fork or resource fork with this name exists + */ + static bool exists(const String &filename); + + /** * Close the Mac data/resource fork pair. */ void close(); diff --git a/common/stream.cpp b/common/stream.cpp index 30b3bca497..85647bfe3a 100644 --- a/common/stream.cpp +++ b/common/stream.cpp @@ -240,7 +240,7 @@ bool SeekableSubReadStream::seek(int32 offset, int whence) { return ret; } -uint32 SafeSubReadStream::read(void *dataPtr, uint32 dataSize) { +uint32 SafeSeekableSubReadStream::read(void *dataPtr, uint32 dataSize) { // Make sure the parent stream is at the right position seek(0, SEEK_CUR); diff --git a/common/substream.h b/common/substream.h index 7e67389da1..01686529aa 100644 --- a/common/substream.h +++ b/common/substream.h @@ -99,21 +99,24 @@ public: * normal SeekableSubReadStream, at the cost of seek()ing the parent stream * before each read(). * - * More than one SafeSubReadStream to the same parent stream can be used + * More than one SafeSeekableSubReadStream to the same parent stream can be used * at the same time; they won't mess up each other. They will, however, * reposition the parent stream, so don't depend on its position to be - * the same after a read() or seek() on one of its SafeSubReadStream. + * the same after a read() or seek() on one of its SafeSeekableSubReadStream. + * + * Note that this stream is *not* threading safe. Calling read from the audio + * thread and from the main thread might mess up the data retrieved. */ -class SafeSubReadStream : public SeekableSubReadStream { +class SafeSeekableSubReadStream : public SeekableSubReadStream { public: - SafeSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO) : - SeekableSubReadStream(parentStream, begin, end, disposeParentStream) { + SafeSeekableSubReadStream(SeekableReadStream *parentStream, uint32 begin, uint32 end, DisposeAfterUse::Flag disposeParentStream = DisposeAfterUse::NO) + : SeekableSubReadStream(parentStream, begin, end, disposeParentStream) { } - virtual uint32 read(void *dataPtr, uint32 dataSize); + virtual uint32 read(void *dataPtr, uint32 dataSize); }; -} // End of namespace Common +} // End of namespace Common #endif diff --git a/common/translation.cpp b/common/translation.cpp index 219fce8794..2bc31c617b 100644 --- a/common/translation.cpp +++ b/common/translation.cpp @@ -232,8 +232,9 @@ bool TranslationManager::openTranslationsFile(File &inFile) { ArchiveMemberList fileList; SearchMan.listMatchingMembers(fileList, "translations.dat"); for (ArchiveMemberList::iterator it = fileList.begin(); it != fileList.end(); ++it) { - SeekableReadStream *stream = it->get()->createReadStream(); - if (stream && inFile.open(stream, it->get()->getName())) { + ArchiveMember const &m = **it; + SeekableReadStream *const stream = m.createReadStream(); + if (stream && inFile.open(stream, m.getName())) { if (checkHeader(inFile)) return true; inFile.close(); |