From 9ab0c3e066b2c0b48daed461e80c7bb22bc6803f Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 14 Apr 2011 23:29:50 +0200 Subject: fix wrong left shift which fixes the invisible fourth player :) --- pacman-c++/actor.cpp | 3 ++- pacman-c++/block.cpp | 3 ++- pacman-c++/constants.h | 2 +- pacman-c++/mainwidget.cpp | 3 ++- pacman-c++/util.cpp | 14 ++++++++++++++ pacman-c++/util.h | 2 ++ 6 files changed, 23 insertions(+), 4 deletions(-) diff --git a/pacman-c++/actor.cpp b/pacman-c++/actor.cpp index 3af304c..e8f5496 100644 --- a/pacman-c++/actor.cpp +++ b/pacman-c++/actor.cpp @@ -1,4 +1,5 @@ #include "actor.h" +#include "util.h" #include #include #include @@ -24,7 +25,7 @@ Actor::Actor(Color::Color color, bool local, QGraphicsItem *parent) return; /* our actor pixmap. created after server part */ - m_pix = ":/" + QString("actor%1").arg((m_color >> 1) + 1); + m_pix = ":/" + QString("actor%1").arg(Util::floorLog2(color) + 1); /* setup icon for player */ m_icon.setPixmap(m_pix); diff --git a/pacman-c++/block.cpp b/pacman-c++/block.cpp index c6aaa73..16f62c4 100644 --- a/pacman-c++/block.cpp +++ b/pacman-c++/block.cpp @@ -1,6 +1,7 @@ #include "block.h" #include "constants.h" #include "actor.h" +#include "util.h" #include QMap Block::m_pixmaps; @@ -14,7 +15,7 @@ Block::Block(Color::Color color, unsigned int neighbours, QGraphicsItem *parent) if (m_pixmaps.find(color) == m_pixmaps.end()) { - unsigned int colid = (color == Color::none) ? 0 : (color >> 1) + 1; + unsigned int colid = (color == Color::none) ? 0 : Util::floorLog2(color) + 1; QString pixmapName = ":/" + QString("block%1").arg(colid); m_pixmaps[color] = QPixmap(pixmapName); } diff --git a/pacman-c++/constants.h b/pacman-c++/constants.h index 7ce26ad..a14e623 100644 --- a/pacman-c++/constants.h +++ b/pacman-c++/constants.h @@ -65,7 +65,7 @@ namespace Transmission const field_t direction_up = (1 << 11); const field_t direction_down = (1 << 12); - const mask_t color_mask = Color::none | Color::red | Color::blue | Color::green; + const mask_t color_mask = Color::none | Color::red | Color::blue | Color::green | Color::yellow; const mask_t type_mask = block | bonuspoint; const mask_t direction_mask = direction_none | direction_left | direction_right | direction_up | direction_down; diff --git a/pacman-c++/mainwidget.cpp b/pacman-c++/mainwidget.cpp index daa5806..705a3ca 100644 --- a/pacman-c++/mainwidget.cpp +++ b/pacman-c++/mainwidget.cpp @@ -72,9 +72,10 @@ void MainWidget::createGui() QGroupBox *scoreBox = new QGroupBox(QString("Player %1").arg(i + 1), this); scoreBox->setObjectName(QString("actor%1").arg(i + 1)); scoreBox->setCheckable(true); + scoreBox->setDisabled(i >= m_maxplayers); connect(scoreBox, SIGNAL(clicked()), this, SLOT(playerScoreClicked())); + scoreBox->setLayout(playerLayout); - scoreBox->setDisabled(i >= m_maxplayers); m_playerScoreLayouts.append(playerLayout); if (Color::order[i] == m_scene->color()) diff --git a/pacman-c++/util.cpp b/pacman-c++/util.cpp index b1848e1..2a3b78a 100644 --- a/pacman-c++/util.cpp +++ b/pacman-c++/util.cpp @@ -248,6 +248,20 @@ namespace Util return data; } + int floorLog2(unsigned int n) + { + if (n == 0) + return -1; + + int pos = 0; + if (n >= 1<<16) { n >>= 16; pos += 16; } + if (n >= 1<< 8) { n >>= 8; pos += 8; } + if (n >= 1<< 4) { n >>= 4; pos += 4; } + if (n >= 1<< 2) { n >>= 2; pos += 2; } + if (n >= 1<< 1) { pos += 1; } + return pos; + } + #if 0 void hexdump(void *pAddressIn, long lSize) { diff --git a/pacman-c++/util.h b/pacman-c++/util.h index 5ea2953..a9ddbee 100644 --- a/pacman-c++/util.h +++ b/pacman-c++/util.h @@ -27,6 +27,8 @@ namespace Util bool sendPacket(const ::google::protobuf::MessageLite& packet, QTcpSocket *socket); QSharedPointer receivePacket(QTcpSocket *socket); + int floorLog2(unsigned int n); + #if 0 void hexdump(void *pAddressIn, long lSize); #endif -- cgit v1.2.3