From f0bef196b19802b2ad544775ee80acfafb057bbf Mon Sep 17 00:00:00 2001 From: Alyssa Milburn Date: Thu, 7 Jul 2011 16:21:09 +0200 Subject: MOHAWK: Maintain ordered list of LB items. --- engines/mohawk/livingbooks.cpp | 14 +++++++++++--- engines/mohawk/livingbooks.h | 3 +++ 2 files changed, 14 insertions(+), 3 deletions(-) (limited to 'engines/mohawk') diff --git a/engines/mohawk/livingbooks.cpp b/engines/mohawk/livingbooks.cpp index f9d18ff7ff..dd7bc9a839 100644 --- a/engines/mohawk/livingbooks.cpp +++ b/engines/mohawk/livingbooks.cpp @@ -204,9 +204,12 @@ Common::Error MohawkEngine_LivingBooks::run() { break; case Common::EVENT_LBUTTONDOWN: - for (uint16 i = 0; i < _items.size(); i++) - if (_items[i]->contains(event.mouse)) - found = _items[i]; + for (Common::List::const_iterator i = _orderedItems.begin(); i != _orderedItems.end(); ++i) { + if ((*i)->contains(event.mouse)) { + found = *i; + break; + } + } if (found) found->handleMouseDown(event.mouse); @@ -341,6 +344,7 @@ void MohawkEngine_LivingBooks::destroyPage() { delete _page; assert(_items.empty()); + assert(_orderedItems.empty()); _page = NULL; _notifyEvents.clear(); @@ -567,6 +571,7 @@ void MohawkEngine_LivingBooks::updatePage() { case kLBDelayedEventDestroy: _items.remove_at(i); i--; + _orderedItems.remove(delayedEvent.item); delete delayedEvent.item; _page->itemDestroyed(delayedEvent.item); if (_focus == delayedEvent.item) @@ -613,6 +618,8 @@ void MohawkEngine_LivingBooks::removeArchive(Archive *archive) { void MohawkEngine_LivingBooks::addItem(LBItem *item) { _items.push_back(item); + _orderedItems.push_front(item); + item->_iterator = _orderedItems.begin(); } void MohawkEngine_LivingBooks::removeItems(const Common::Array &items) { @@ -626,6 +633,7 @@ void MohawkEngine_LivingBooks::removeItems(const Common::Array &items) break; } assert(found); + _orderedItems.erase(items[i]->_iterator); } } diff --git a/engines/mohawk/livingbooks.h b/engines/mohawk/livingbooks.h index ad2fe56a52..c86a3cc055 100644 --- a/engines/mohawk/livingbooks.h +++ b/engines/mohawk/livingbooks.h @@ -405,6 +405,8 @@ public: uint16 getSoundPriority() { return _soundMode; } bool isAmbient() { return _isAmbient; } + Common::List::iterator _iterator; + protected: MohawkEngine_LivingBooks *_vm; LBPage *_page; @@ -714,6 +716,7 @@ private: uint16 _phase; LBPage *_page; Common::Array _items; + Common::List _orderedItems; Common::Queue _eventQueue; LBItem *_focus; void destroyPage(); -- cgit v1.2.3