From 7c7e0445eed953e4af155932625e6dddc2cf4c9b Mon Sep 17 00:00:00 2001 From: Filippos Karapetis Date: Sun, 4 Oct 2009 18:51:01 +0000 Subject: Replaced DblList with Common::List svn-id: r44630 --- engines/sci/gui/gui_dbllist.cpp | 257 -------------------------------------- engines/sci/gui/gui_dbllist.h | 74 ----------- engines/sci/gui/gui_helpers.h | 11 -- engines/sci/gui/gui_windowmgr.cpp | 35 ++++-- engines/sci/gui/gui_windowmgr.h | 7 +- engines/sci/module.mk | 1 - 6 files changed, 27 insertions(+), 358 deletions(-) delete mode 100644 engines/sci/gui/gui_dbllist.cpp delete mode 100644 engines/sci/gui/gui_dbllist.h (limited to 'engines/sci') diff --git a/engines/sci/gui/gui_dbllist.cpp b/engines/sci/gui/gui_dbllist.cpp deleted file mode 100644 index 55aa4b039b..0000000000 --- a/engines/sci/gui/gui_dbllist.cpp +++ /dev/null @@ -1,257 +0,0 @@ -/* 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. - * - * $URL$ - * $Id$ - * - */ - -#include "common/util.h" - -#include "sci/sci.h" -#include "sci/gui/gui_helpers.h" -#include "sci/gui/gui_memmgr.h" -#include "sci/gui/gui_dbllist.h" - -namespace Sci { - -DblList::DblList() { - _hFirst = 0; - _hLast = 0; -} - -DblList::DblList(HEAPHANDLE heap) { - byte *ptr = heap2Ptr(heap); - _hFirst = READ_UINT16(ptr); - _hLast = READ_UINT16(ptr + 2); -} - -DblList::~DblList(void) { -} -//-------------------------------------- -// Prints all list contents -void DblList::Dump(char*caption) { - debug("DumpList %s:", caption); - debug(" First: %04X Last: %04X", _hFirst, _hLast); - HEAPHANDLE node = _hFirst; - while (node) { - GUINode *pNode = (GUINode *)heap2Ptr(node); - debug(" %04X key=%04X prev=%04X next=%04X add.data=%db", node, - pNode->key, pNode->prev, pNode->next, heapGetDataSize(node) - 6); - node = pNode->next; - } - debug("End of list"); -} -//-------------------------------------- -// Add a new node to front of the list -HEAPHANDLE DblList::AddToFront(HEAPHANDLE node, uint16 key) { - if (!node) { - warning("Bad node handler (%04X) passed to DblList::AddToFront !", - node); - return node; - } - GUINode *pNode = (GUINode *)heap2Ptr(node); - pNode->key = key; - if (_hFirst) { // we already have a 1st node - GUINode *pnext = (GUINode *)heap2Ptr(_hFirst); - pnext->prev = node; - pNode->next = _hFirst; - } else { // list is empty, to passed node becames 1st one - _hLast = node; - pNode->next = 0; - } - _hFirst = node; - pNode->prev = 0; - return node; -} - -//------------------------------------- -// -HEAPHANDLE DblList::AddToEnd(HEAPHANDLE node, uint16 key) { - if (!node) { - warning("Bad node handler (%04X) passed to DblList::AddToEnd !", node); - return node; - } - GUINode *pNode = (GUINode *)heap2Ptr(node); - if (_hFirst) { // list is not empty - GUINode *plast = (GUINode *)heap2Ptr(_hLast); - plast->next = node; - pNode->prev = _hLast; - } else { // list is empty, so the node becames 1st one - _hFirst = node; - pNode->prev = 0; - } - _hLast = node; - pNode->next = 0; - pNode->key = key; - - return node; -} - -//------------------------------------------------ -// returns node that contains the key -HEAPHANDLE DblList::FindKey(uint16 key) { - HEAPHANDLE node = _hFirst; - while (node) { - GUINode *pNode = (GUINode *)heap2Ptr(node); - if (pNode->key == key) - break; - node = pNode->next; - } - return node; -} -//------------------------------------------------ -// detaches node with specified key and returning the node -HEAPHANDLE DblList::DeleteKey(uint16 key) { - HEAPHANDLE node = FindKey(key); - if (node) - DeleteNode(node); - return node; -} -//------------------------------------------------ -// detaches specified node from list -byte DblList::DeleteNode(HEAPHANDLE node) { - if (!node) { - warning("Bad node handler (%04X) passed to DblList::AddToEnd !", node); - return node; - } - // updating the links - GUINode *pNode = (GUINode *)heap2Ptr(node); - if (pNode->prev) { - GUINode *pprev = (GUINode *)heap2Ptr(pNode->prev); - pprev->next = pNode->next; - } - if (pNode->next) { - GUINode *pnext = (GUINode *)heap2Ptr(pNode->next); - pnext->prev = pNode->prev; - } - // updating list head if needed - if (_hFirst == node) - _hFirst = pNode->next; - if (_hLast == node) - _hLast = pNode->prev; - pNode->prev = 0; - pNode->next = 0; - return 1; -} -//------------------------------------------------ -// Moves node to the end of the list -HEAPHANDLE DblList::MoveToEnd(HEAPHANDLE node) { - if (!node) { - warning("Bad node handler (%04X) passed to DblList::MoveToEnd !", node); - return node; - } - GUINode *pNode = (GUINode *)heap2Ptr(node); - if (pNode->next) { // node is not the last one in list - DeleteNode(node); - AddToEnd(node, pNode->key); - } - return node; -} -//------------------------------------------------ -// Moves node to the front of the list -HEAPHANDLE DblList::MoveToFront(HEAPHANDLE node) { - if (!node) { - warning("Bad node handler (%04X) passed to DblList::MoveToFront !", - node); - return node; - } - GUINode *pNode = (GUINode *)heap2Ptr(node); - if (pNode->prev) { // node is not 1st one in list - DeleteNode(node); - AddToFront(node, pNode->key); - } - return node; -} -//------------------------------------------------ -HEAPHANDLE DblList::AddAfter(HEAPHANDLE ref, HEAPHANDLE node, uint16 key) { - if (!node) { - warning("Bad node handler (%04X) passed to DblList::AddAfter !", node); - return node; - } - GUINode *pNode = (GUINode *)heap2Ptr(node); - GUINode *pref = (GUINode *)heap2Ptr(ref); - pNode->key = key; - if (pref->next == 0) { // ref node is the last one - pNode->next = 0; - _hLast = node; - } else { - GUINode *pnext = (GUINode *)heap2Ptr(pref->next); - pNode->next = pref->next; - pnext->prev = node; - } - pref->next = node; - pNode->prev = ref; - return node; -} -//------------------------------------------------ -// -HEAPHANDLE DblList::AddBefore(HEAPHANDLE ref, HEAPHANDLE node, uint16 key) { - if (!node) { - warning("Bad node handler (%04X) passed to DblList::AddBefore !", node); - return node; - } - GUINode *pNode = (GUINode *)heap2Ptr(node); - GUINode *pref = (GUINode *)heap2Ptr(ref); - pNode->key = key; - if (pref->prev == 0) { // ref node is the 1st one - pNode->prev = 0; - _hFirst = node; - } else { - GUINode*pprev = (GUINode *)heap2Ptr(pref->prev); - pNode->prev = pref->prev; - pprev->next = node; - } - pref->prev = node; - pNode->next = ref; - return node; -} -//------------------------------------------------ -void DblList::toHeap(HEAPHANDLE heap) { - byte *ptr = heap2Ptr(heap); - WRITE_UINT16(ptr, _hFirst); - WRITE_UINT16(ptr + 2, _hLast); -} -//------------------------------------------------ -void DblList::DeleteList() { - HEAPHANDLE node = getFirst(), next; - GUINode *pNode; - while (node) { - pNode = (GUINode *)heap2Ptr(node); - next = pNode->next; - heapDisposePtr(node); - node = next; - } - _hFirst = _hLast = 0; -} -//------------------------------------------------ -uint16 DblList::getSize() { - uint16 cnt = 0; - HEAPHANDLE node = getFirst(); - GUINode *pNode; - while (node) { - pNode = (GUINode *)heap2Ptr(node); - node = pNode->next; - cnt++; - } - return cnt; -} -//------------------------------------------------ -} // end of namespace diff --git a/engines/sci/gui/gui_dbllist.h b/engines/sci/gui/gui_dbllist.h deleted file mode 100644 index fe3cd36f7b..0000000000 --- a/engines/sci/gui/gui_dbllist.h +++ /dev/null @@ -1,74 +0,0 @@ -/* 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. - * - * $URL$ - * $Id$ - * - */ - -/* - Each node contains handles to next and previous node and an optional key for searching - Head node contains handles to first and last node - */ - -namespace Sci { - -typedef uint16 HEAPHANDLE; - -class DblList { -public: - DblList(); - DblList(HEAPHANDLE heap); - ~DblList(void); -protected: - HEAPHANDLE _hFirst, _hLast; -public: - // Add a new node to front of the list - HEAPHANDLE AddToFront(HEAPHANDLE node, uint16 key = 0); - HEAPHANDLE AddToEnd(HEAPHANDLE node, uint16 key = 0); - HEAPHANDLE MoveToEnd(HEAPHANDLE node); - HEAPHANDLE MoveToFront(HEAPHANDLE node); - HEAPHANDLE AddAfter(HEAPHANDLE ref, HEAPHANDLE node, uint16 key = 0); - HEAPHANDLE AddBefore(HEAPHANDLE ref, HEAPHANDLE node, uint16 key = 0); - - HEAPHANDLE FindKey(uint16 key); - HEAPHANDLE DeleteKey(uint16 key); - byte DeleteNode(HEAPHANDLE node); - void DeleteList(); - void Dump(char*caption = ""); // for debug - HEAPHANDLE getFirst() { - return _hFirst; - } - HEAPHANDLE getLast() { - return _hLast; - } - void toHeap(HEAPHANDLE heap); - bool isEmpty() { - return (_hFirst == 0 && _hLast == 0); - } - uint16 getSize(); - void set(HEAPHANDLE first, HEAPHANDLE last){ - _hFirst = first; - _hLast = last; - } - -}; - -} // end of namespace diff --git a/engines/sci/gui/gui_helpers.h b/engines/sci/gui/gui_helpers.h index 2ef7adc995..e94bbe8942 100644 --- a/engines/sci/gui/gui_helpers.h +++ b/engines/sci/gui/gui_helpers.h @@ -35,17 +35,7 @@ typedef int16 GUIViewCellNo; typedef uint16 GUIHandle; -struct GUINode { - GUIHandle next; // heap handle to next node - GUIHandle prev; // heap handle to data - uint16 key; // maybe also a heap handle -}; -struct GUINode1 : GUINode { - uint16 value; -}; - struct GUIPort { - GUINode node; // node struct for list operations int16 top, left; Common::Rect rect; int16 curTop, curLeft; @@ -67,7 +57,6 @@ struct GUIWindow : public GUIPort { }; struct GUICast { - GUINode node; uint16 view; uint16 loop; uint16 cel; diff --git a/engines/sci/gui/gui_windowmgr.cpp b/engines/sci/gui/gui_windowmgr.cpp index e3ea6452cb..e16a1bf1a0 100644 --- a/engines/sci/gui/gui_windowmgr.cpp +++ b/engines/sci/gui/gui_windowmgr.cpp @@ -23,6 +23,7 @@ * */ +#include "common/algorithm.h" // for Common::find() #include "common/util.h" #include "sci/sci.h" @@ -68,7 +69,7 @@ SciGUIwindowMgr::SciGUIwindowMgr(EngineState *state, SciGUIgfx *gfx) _wmgrPort->curTop = 0; _wmgrPort->curLeft = 0; - windowList.AddToFront(wmgrPortH); + windowList.push_front(wmgrPortH); _picWind = NewWindow(s_picRect, 0, 0, kTransparent | kNoFrame, 0, 1); } @@ -77,7 +78,7 @@ SciGUIwindowMgr::~SciGUIwindowMgr() { } int16 SciGUIwindowMgr::isFrontWindow(GUIWindow *pWnd) { - if (heap2Ptr(windowList.getLast()) == (byte *)pWnd) + if (heap2Ptr(windowList.back()) == (byte *)pWnd) return 1; return 0; } @@ -85,10 +86,14 @@ int16 SciGUIwindowMgr::isFrontWindow(GUIWindow *pWnd) { void SciGUIwindowMgr::SelectWindow(HEAPHANDLE hh) { GUIPort *port = (GUIPort *)heap2Ptr(hh); _gfx->SetPort(port); - if (hh != windowList.getLast()) { // selecting not topmost window - GUIWindow *prevwnd = (GUIWindow *)heap2Ptr(port->node.prev); + if (hh != windowList.back()) { // selecting not topmost window + Common::List::iterator curWindowIterator = Common::find(windowList.begin(), windowList.end(), hh); + Common::List::iterator prevWindowIterator = --curWindowIterator; + curWindowIterator++; // restore iterator position + GUIWindow *prevwnd = (GUIWindow *)heap2Ptr(*prevWindowIterator); BeginUpdate(prevwnd); - windowList.MoveToEnd(hh); + windowList.erase(curWindowIterator); + windowList.push_back(hh); EndUpdate(prevwnd); } _gfx->SetPort(port); @@ -96,19 +101,23 @@ void SciGUIwindowMgr::SelectWindow(HEAPHANDLE hh) { void SciGUIwindowMgr::BeginUpdate(GUIWindow *wnd) { GUIPort *oldPort = _gfx->SetPort(_wmgrPort); - GUIWindow *node = (GUIWindow *)heap2Ptr(windowList.getLast()); + Common::List::iterator curWindowIterator = windowList.end(); + GUIWindow *node = (GUIWindow *)heap2Ptr(*curWindowIterator); while (node != wnd) { UpdateWindow(node); - node = (GUIWindow *)heap2Ptr(node->node.prev); + curWindowIterator--; // previous node + node = (GUIWindow *)heap2Ptr(*curWindowIterator); } _gfx->SetPort(oldPort); } void SciGUIwindowMgr::EndUpdate(GUIWindow *wnd) { GUIPort *oldPort = _gfx->SetPort(_wmgrPort); - GUIWindow *last = (GUIWindow *)heap2Ptr(windowList.getLast()); + Common::List::iterator curWindowIterator = windowList.end(); + GUIWindow *last = (GUIWindow *)heap2Ptr(*curWindowIterator); while (wnd != last) { - wnd = (GUIWindow *)heap2Ptr(wnd->node.next); + curWindowIterator++; // next node + wnd = (GUIWindow *)heap2Ptr(*curWindowIterator); UpdateWindow(wnd); } _gfx->SetPort(oldPort); @@ -124,9 +133,9 @@ GUIWindow *SciGUIwindowMgr::NewWindow(const Common::Rect &dims, const Common::Re } heapClearPtr(hWnd); if (style & kTopmost) - windowList.AddToFront(hWnd); + windowList.push_front(hWnd); else - windowList.AddToEnd(hWnd); + windowList.push_back(hWnd); GUIWindow *pwnd = (GUIWindow *)heap2Ptr(hWnd); _gfx->OpenPort((GUIPort *)pwnd); r = dims; @@ -250,8 +259,8 @@ void SciGUIwindowMgr::DisposeWindow(GUIWindow *pWnd, int16 arg2) { // else // g_sci->ReAnimate(&pwnd->dims); HEAPHANDLE hh = ptr2heap((byte *)pWnd); - windowList.DeleteNode(hh); - SelectWindow(windowList.getLast()); + windowList.remove(hh); + SelectWindow(windowList.back()); if (pWnd->hTitle) heapDisposePtr(pWnd->hTitle); heapDisposePtr(hh); diff --git a/engines/sci/gui/gui_windowmgr.h b/engines/sci/gui/gui_windowmgr.h index 58db720663..10986d8791 100644 --- a/engines/sci/gui/gui_windowmgr.h +++ b/engines/sci/gui/gui_windowmgr.h @@ -23,10 +23,13 @@ * */ -#include "sci/gui/gui_dbllist.h" +#include "common/list.h" namespace Sci { +// TODO: remove HEAPHANDLE and make a list of GUIWindow pointers instead +typedef uint16 HEAPHANDLE; + class SciGUIwindowMgr { public: SciGUIwindowMgr(EngineState *state, SciGUIgfx *gfx); @@ -48,7 +51,7 @@ private: EngineState *_s; SciGUIgfx *_gfx; - DblList windowList; + Common::List windowList; }; } // end of namespace Sci diff --git a/engines/sci/module.mk b/engines/sci/module.mk index fd5b7aaaed..00ccb917dd 100644 --- a/engines/sci/module.mk +++ b/engines/sci/module.mk @@ -56,7 +56,6 @@ MODULE_OBJS = \ gfx/res_view.o \ gfx/seq_decoder.o \ gui/gui.o \ - gui/gui_dbllist.o \ gui/gui_font.o \ gui/gui_gfx.o \ gui/gui_memmgr.o \ -- cgit v1.2.3