From 24c0b3fd325e204cc3edbb656bb52c631bd7182a Mon Sep 17 00:00:00 2001 From: crs Date: Thu, 16 Jan 2003 21:28:15 +0000 Subject: [PATCH] Fixed lookup of neighbor screens. The first problem was an old code in a conditional for moving left that blew an assert verifying that the mouse position was really on the screen if the neighbor screen wasn't connected. After that was fixed there was another problem when one screen linked to another which then linked (in the same direction) to itself. If the latter screen wasn't connected then it'd get into an infinite loop. --- lib/server/CServer.cpp | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/server/CServer.cpp b/lib/server/CServer.cpp index d72b33c2..9ae41237 100644 --- a/lib/server/CServer.cpp +++ b/lib/server/CServer.cpp @@ -841,30 +841,44 @@ CServer::getNeighbor(IClient* src, EDirection dir) const assert(src != NULL); + // get source screen name CString srcName = src->getName(); assert(!srcName.empty()); LOG((CLOG_DEBUG2 "find neighbor on %s of \"%s\"", CConfig::dirName(dir), srcName.c_str())); - for (;;) { - // look up name of neighbor - const CString dstName(m_config.getNeighbor(srcName, dir)); - // if nothing in that direction then return NULL - if (dstName.empty()) { + // get first neighbor. if it's the source then the source jumps + // to itself and we return the source. + CString dstName(m_config.getNeighbor(srcName, dir)); + if (dstName == srcName) { + LOG((CLOG_DEBUG2 "\"%s\" is on %s of \"%s\"", dstName.c_str(), CConfig::dirName(dir), srcName.c_str())); + return src; + } + + // keep checking + for (;;) { + // if nothing in that direction then return NULL. if the + // destination is the source then we can make no more + // progress in this direction. since we haven't found a + // connected neighbor we return NULL. + if (dstName.empty() || dstName == srcName) { LOG((CLOG_DEBUG2 "no neighbor on %s of \"%s\"", CConfig::dirName(dir), srcName.c_str())); return NULL; } // look up neighbor cell. if the screen is connected and - // ready then we can stop. otherwise we skip over an - // unconnected screen. + // ready then we can stop. CClientList::const_iterator index = m_clients.find(dstName); if (index != m_clients.end()) { LOG((CLOG_DEBUG2 "\"%s\" is on %s of \"%s\"", dstName.c_str(), CConfig::dirName(dir), srcName.c_str())); return index->second; } + // skip over unconnected screen LOG((CLOG_DEBUG2 "ignored \"%s\" on %s of \"%s\"", dstName.c_str(), CConfig::dirName(dir), srcName.c_str())); srcName = dstName; + + // look up name of neighbor of skipped screen + dstName = m_config.getNeighbor(srcName, dir); } } @@ -897,7 +911,7 @@ CServer::getNeighbor(IClient* src, switch (srcSide) { case kLeft: x -= dx; - while (dst != NULL && dst != lastGoodScreen) { + while (dst != NULL) { lastGoodScreen = dst; lastGoodScreen->getShape(dx, dy, dw, dh); x += dw;