diff options
| -rw-r--r-- | pacman-c++/actor.cpp | 3 | ||||
| -rw-r--r-- | pacman-c++/block.cpp | 3 | ||||
| -rw-r--r-- | pacman-c++/constants.h | 2 | ||||
| -rw-r--r-- | pacman-c++/mainwidget.cpp | 3 | ||||
| -rw-r--r-- | pacman-c++/util.cpp | 14 | ||||
| -rw-r--r-- | 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 @@ | |||
| 1 | #include "actor.h" | 1 | #include "actor.h" |
| 2 | #include "util.h" | ||
| 2 | #include <QtCore/QPropertyAnimation> | 3 | #include <QtCore/QPropertyAnimation> |
| 3 | #include <QtCore/QVariantAnimation> | 4 | #include <QtCore/QVariantAnimation> |
| 4 | #include <QDebug> | 5 | #include <QDebug> |
| @@ -24,7 +25,7 @@ Actor::Actor(Color::Color color, bool local, QGraphicsItem *parent) | |||
| 24 | return; | 25 | return; |
| 25 | 26 | ||
| 26 | /* our actor pixmap. created after server part */ | 27 | /* our actor pixmap. created after server part */ |
| 27 | m_pix = ":/" + QString("actor%1").arg((m_color >> 1) + 1); | 28 | m_pix = ":/" + QString("actor%1").arg(Util::floorLog2(color) + 1); |
| 28 | 29 | ||
| 29 | /* setup icon for player */ | 30 | /* setup icon for player */ |
| 30 | m_icon.setPixmap(m_pix); | 31 | 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 @@ | |||
| 1 | #include "block.h" | 1 | #include "block.h" |
| 2 | #include "constants.h" | 2 | #include "constants.h" |
| 3 | #include "actor.h" | 3 | #include "actor.h" |
| 4 | #include "util.h" | ||
| 4 | #include <QtDebug> | 5 | #include <QtDebug> |
| 5 | 6 | ||
| 6 | QMap<Color::Color, QPixmap> Block::m_pixmaps; | 7 | QMap<Color::Color, QPixmap> Block::m_pixmaps; |
| @@ -14,7 +15,7 @@ Block::Block(Color::Color color, unsigned int neighbours, QGraphicsItem *parent) | |||
| 14 | 15 | ||
| 15 | if (m_pixmaps.find(color) == m_pixmaps.end()) | 16 | if (m_pixmaps.find(color) == m_pixmaps.end()) |
| 16 | { | 17 | { |
| 17 | unsigned int colid = (color == Color::none) ? 0 : (color >> 1) + 1; | 18 | unsigned int colid = (color == Color::none) ? 0 : Util::floorLog2(color) + 1; |
| 18 | QString pixmapName = ":/" + QString("block%1").arg(colid); | 19 | QString pixmapName = ":/" + QString("block%1").arg(colid); |
| 19 | m_pixmaps[color] = QPixmap(pixmapName); | 20 | m_pixmaps[color] = QPixmap(pixmapName); |
| 20 | } | 21 | } |
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 | |||
| 65 | const field_t direction_up = (1 << 11); | 65 | const field_t direction_up = (1 << 11); |
| 66 | const field_t direction_down = (1 << 12); | 66 | const field_t direction_down = (1 << 12); |
| 67 | 67 | ||
| 68 | const mask_t color_mask = Color::none | Color::red | Color::blue | Color::green; | 68 | const mask_t color_mask = Color::none | Color::red | Color::blue | Color::green | Color::yellow; |
| 69 | const mask_t type_mask = block | bonuspoint; | 69 | const mask_t type_mask = block | bonuspoint; |
| 70 | const mask_t direction_mask = direction_none | direction_left | direction_right | direction_up | direction_down; | 70 | const mask_t direction_mask = direction_none | direction_left | direction_right | direction_up | direction_down; |
| 71 | 71 | ||
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() | |||
| 72 | QGroupBox *scoreBox = new QGroupBox(QString("Player %1").arg(i + 1), this); | 72 | QGroupBox *scoreBox = new QGroupBox(QString("Player %1").arg(i + 1), this); |
| 73 | scoreBox->setObjectName(QString("actor%1").arg(i + 1)); | 73 | scoreBox->setObjectName(QString("actor%1").arg(i + 1)); |
| 74 | scoreBox->setCheckable(true); | 74 | scoreBox->setCheckable(true); |
| 75 | scoreBox->setDisabled(i >= m_maxplayers); | ||
| 75 | connect(scoreBox, SIGNAL(clicked()), this, SLOT(playerScoreClicked())); | 76 | connect(scoreBox, SIGNAL(clicked()), this, SLOT(playerScoreClicked())); |
| 77 | |||
| 76 | scoreBox->setLayout(playerLayout); | 78 | scoreBox->setLayout(playerLayout); |
| 77 | scoreBox->setDisabled(i >= m_maxplayers); | ||
| 78 | m_playerScoreLayouts.append(playerLayout); | 79 | m_playerScoreLayouts.append(playerLayout); |
| 79 | 80 | ||
| 80 | if (Color::order[i] == m_scene->color()) | 81 | 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 | |||
| 248 | return data; | 248 | return data; |
| 249 | } | 249 | } |
| 250 | 250 | ||
| 251 | int floorLog2(unsigned int n) | ||
| 252 | { | ||
| 253 | if (n == 0) | ||
| 254 | return -1; | ||
| 255 | |||
| 256 | int pos = 0; | ||
| 257 | if (n >= 1<<16) { n >>= 16; pos += 16; } | ||
| 258 | if (n >= 1<< 8) { n >>= 8; pos += 8; } | ||
| 259 | if (n >= 1<< 4) { n >>= 4; pos += 4; } | ||
| 260 | if (n >= 1<< 2) { n >>= 2; pos += 2; } | ||
| 261 | if (n >= 1<< 1) { pos += 1; } | ||
| 262 | return pos; | ||
| 263 | } | ||
| 264 | |||
| 251 | #if 0 | 265 | #if 0 |
| 252 | void hexdump(void *pAddressIn, long lSize) | 266 | void hexdump(void *pAddressIn, long lSize) |
| 253 | { | 267 | { |
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 | |||
| 27 | bool sendPacket(const ::google::protobuf::MessageLite& packet, QTcpSocket *socket); | 27 | bool sendPacket(const ::google::protobuf::MessageLite& packet, QTcpSocket *socket); |
| 28 | QSharedPointer<QByteArray> receivePacket(QTcpSocket *socket); | 28 | QSharedPointer<QByteArray> receivePacket(QTcpSocket *socket); |
| 29 | 29 | ||
| 30 | int floorLog2(unsigned int n); | ||
| 31 | |||
| 30 | #if 0 | 32 | #if 0 |
| 31 | void hexdump(void *pAddressIn, long lSize); | 33 | void hexdump(void *pAddressIn, long lSize); |
| 32 | #endif | 34 | #endif |
