diff options
| -rw-r--r-- | pacman-c++/actor.cpp | 22 | ||||
| -rw-r--r-- | pacman-c++/actor.h | 15 | ||||
| -rw-r--r-- | pacman-c++/audio.cpp | 7 | ||||
| -rw-r--r-- | pacman-c++/block.h | 4 | ||||
| -rw-r--r-- | pacman-c++/bonuspoint.h | 3 | ||||
| -rw-r--r-- | pacman-c++/client.cpp | 2 | ||||
| -rw-r--r-- | pacman-c++/mainwidget.cpp | 57 | ||||
| -rw-r--r-- | pacman-c++/mainwidget.h | 2 | ||||
| -rw-r--r-- | pacman-c++/pacman.proto | 1 | ||||
| -rw-r--r-- | pacman-c++/pixmapitem.h | 4 | ||||
| -rw-r--r-- | pacman-c++/point.h | 3 | ||||
| -rw-r--r-- | pacman-c++/sceneholder.cpp | 29 | ||||
| -rw-r--r-- | pacman-c++/sceneholder.h | 7 | ||||
| -rw-r--r-- | pacman-c++/server.cpp | 77 | ||||
| -rw-r--r-- | pacman-c++/util.cpp | 52 | ||||
| -rw-r--r-- | pacman-c++/util.h | 7 |
16 files changed, 183 insertions, 109 deletions
diff --git a/pacman-c++/actor.cpp b/pacman-c++/actor.cpp index 8184c6f..e34d338 100644 --- a/pacman-c++/actor.cpp +++ b/pacman-c++/actor.cpp | |||
| @@ -202,3 +202,25 @@ void Actor::eatingCherry() | |||
| 202 | return; | 202 | return; |
| 203 | AudioManager::self()->play(Sound::EatingCherry); | 203 | AudioManager::self()->play(Sound::EatingCherry); |
| 204 | } | 204 | } |
| 205 | |||
| 206 | unsigned int Actor::getRoundPoints() | ||
| 207 | { | ||
| 208 | return m_roundPoints; | ||
| 209 | } | ||
| 210 | |||
| 211 | unsigned int Actor::getGamePoints() | ||
| 212 | { | ||
| 213 | return m_gamePoints; | ||
| 214 | } | ||
| 215 | |||
| 216 | void Actor::addRoundPoints(unsigned int amount) | ||
| 217 | { | ||
| 218 | m_roundPoints += amount; | ||
| 219 | } | ||
| 220 | |||
| 221 | void Actor::finishRound() | ||
| 222 | { | ||
| 223 | m_gamePoints += m_roundPoints; | ||
| 224 | m_roundPoints = 0; | ||
| 225 | } | ||
| 226 | |||
diff --git a/pacman-c++/actor.h b/pacman-c++/actor.h index 78b7c01..19d672b 100644 --- a/pacman-c++/actor.h +++ b/pacman-c++/actor.h | |||
| @@ -23,7 +23,8 @@ public: | |||
| 23 | }; | 23 | }; |
| 24 | 24 | ||
| 25 | Actor(Color::Color color, bool local = false, QGraphicsItem *parent = 0); | 25 | Actor(Color::Color color, bool local = false, QGraphicsItem *parent = 0); |
| 26 | virtual ~Actor() {}; | 26 | virtual ~Actor() |
| 27 | {}; | ||
| 27 | 28 | ||
| 28 | QSequentialAnimationGroup *setupEatingAnimation(Actor::Movement direction); | 29 | QSequentialAnimationGroup *setupEatingAnimation(Actor::Movement direction); |
| 29 | Color::Color getColor(); | 30 | Color::Color getColor(); |
| @@ -34,11 +35,10 @@ public: | |||
| 34 | void die(); | 35 | void die(); |
| 35 | void eatingCherry(); | 36 | void eatingCherry(); |
| 36 | 37 | ||
| 37 | unsigned int getRoundPoints() { return m_roundPoints; } | 38 | unsigned int getRoundPoints(); |
| 38 | unsigned int getGamePoints() { return m_gamePoints; } | 39 | unsigned int getGamePoints(); |
| 39 | 40 | void addRoundPoints(unsigned int amount); | |
| 40 | void addRoundPoints(unsigned int amount) { m_roundPoints += amount; } | 41 | void finishRound(); |
| 41 | void finishRound() { m_gamePoints += m_roundPoints; m_roundPoints = 0; } | ||
| 42 | 42 | ||
| 43 | private: | 43 | private: |
| 44 | QPixmap m_pix; | 44 | QPixmap m_pix; |
| @@ -48,7 +48,8 @@ private: | |||
| 48 | bool m_local; | 48 | bool m_local; |
| 49 | AudioPlayer *m_player; | 49 | AudioPlayer *m_player; |
| 50 | 50 | ||
| 51 | unsigned int m_roundPoints, m_gamePoints; | 51 | unsigned int m_roundPoints; |
| 52 | unsigned int m_gamePoints; | ||
| 52 | 53 | ||
| 53 | QList<PixmapItem *> m_images; | 54 | QList<PixmapItem *> m_images; |
| 54 | QList<QSequentialAnimationGroup *> m_eating; | 55 | QList<QSequentialAnimationGroup *> m_eating; |
diff --git a/pacman-c++/audio.cpp b/pacman-c++/audio.cpp index 0692cd1..ebeda2b 100644 --- a/pacman-c++/audio.cpp +++ b/pacman-c++/audio.cpp | |||
| @@ -22,6 +22,8 @@ AudioManager::AudioManager() | |||
| 22 | m_players.append(firstplayer); | 22 | m_players.append(firstplayer); |
| 23 | 23 | ||
| 24 | m_muted = false; | 24 | m_muted = false; |
| 25 | #else | ||
| 26 | qDebug() << "Server has no sound" | ||
| 25 | #endif // SERVER | 27 | #endif // SERVER |
| 26 | } | 28 | } |
| 27 | 29 | ||
| @@ -61,7 +63,6 @@ void AudioManager::pause() | |||
| 61 | { | 63 | { |
| 62 | if (!isWorking()) | 64 | if (!isWorking()) |
| 63 | return; | 65 | return; |
| 64 | qDebug() << "pause"; | ||
| 65 | for(int i = 0; i < m_players.count(); ++i) | 66 | for(int i = 0; i < m_players.count(); ++i) |
| 66 | m_players.at(i)->pause(); | 67 | m_players.at(i)->pause(); |
| 67 | } | 68 | } |
| @@ -70,7 +71,6 @@ void AudioManager::stop() | |||
| 70 | { | 71 | { |
| 71 | if (!isWorking()) | 72 | if (!isWorking()) |
| 72 | return; | 73 | return; |
| 73 | qDebug() << "stop"; | ||
| 74 | for(int i = 0; i < m_players.count(); ++i) | 74 | for(int i = 0; i < m_players.count(); ++i) |
| 75 | m_players.at(i)->stop(); | 75 | m_players.at(i)->stop(); |
| 76 | } | 76 | } |
| @@ -79,7 +79,6 @@ void AudioManager::clear() | |||
| 79 | { | 79 | { |
| 80 | if (!isWorking()) | 80 | if (!isWorking()) |
| 81 | return; | 81 | return; |
| 82 | qDebug() << "clear"; | ||
| 83 | for(int i = 0; i < m_players.count(); ++i) | 82 | for(int i = 0; i < m_players.count(); ++i) |
| 84 | m_players.at(i)->clear(); | 83 | m_players.at(i)->clear(); |
| 85 | } | 84 | } |
| @@ -105,7 +104,6 @@ void AudioManager::play(Sound::Type sound) | |||
| 105 | return; | 104 | return; |
| 106 | } | 105 | } |
| 107 | 106 | ||
| 108 | qDebug() << "play"; | ||
| 109 | AudioPlayer *player = audioPlayer(); | 107 | AudioPlayer *player = audioPlayer(); |
| 110 | player->setCurrentSource(Phonon::MediaSource(m_sounds[sound])); | 108 | player->setCurrentSource(Phonon::MediaSource(m_sounds[sound])); |
| 111 | player->play(); | 109 | player->play(); |
| @@ -115,7 +113,6 @@ void AudioManager::enqueue(Sound::Type sound) | |||
| 115 | { | 113 | { |
| 116 | if (!isWorking()) | 114 | if (!isWorking()) |
| 117 | return; | 115 | return; |
| 118 | qDebug() << "manager enqueue"; | ||
| 119 | audioPlayer()->enqueue(Phonon::MediaSource(m_sounds[sound])); | 116 | audioPlayer()->enqueue(Phonon::MediaSource(m_sounds[sound])); |
| 120 | } | 117 | } |
| 121 | 118 | ||
diff --git a/pacman-c++/block.h b/pacman-c++/block.h index 851f45c..17f1813 100644 --- a/pacman-c++/block.h +++ b/pacman-c++/block.h | |||
| @@ -19,8 +19,8 @@ public: | |||
| 19 | 19 | ||
| 20 | public: | 20 | public: |
| 21 | Block(Color::Color color, unsigned int neighbours = None, QGraphicsItem *parent = 0); | 21 | Block(Color::Color color, unsigned int neighbours = None, QGraphicsItem *parent = 0); |
| 22 | virtual ~Block() {}; | 22 | virtual ~Block() |
| 23 | 23 | {}; | |
| 24 | 24 | ||
| 25 | void setNeighbours(unsigned int neighbours); | 25 | void setNeighbours(unsigned int neighbours); |
| 26 | 26 | ||
diff --git a/pacman-c++/bonuspoint.h b/pacman-c++/bonuspoint.h index f0fc550..d204f72 100644 --- a/pacman-c++/bonuspoint.h +++ b/pacman-c++/bonuspoint.h | |||
| @@ -8,7 +8,8 @@ class BonusPoint | |||
| 8 | { | 8 | { |
| 9 | public: | 9 | public: |
| 10 | BonusPoint(QGraphicsItem *parent=0); | 10 | BonusPoint(QGraphicsItem *parent=0); |
| 11 | virtual ~BonusPoint() {}; | 11 | virtual ~BonusPoint() |
| 12 | {}; | ||
| 12 | }; | 13 | }; |
| 13 | 14 | ||
| 14 | #endif // BONUSPOINT_H | 15 | #endif // BONUSPOINT_H |
diff --git a/pacman-c++/client.cpp b/pacman-c++/client.cpp index 394b446..d885e49 100644 --- a/pacman-c++/client.cpp +++ b/pacman-c++/client.cpp | |||
| @@ -26,7 +26,7 @@ void Client::createMenu() | |||
| 26 | toggleSound->setAlignment(Qt::AlignBottom); | 26 | toggleSound->setAlignment(Qt::AlignBottom); |
| 27 | 27 | ||
| 28 | bool sound = AudioManager::self()->isWorking(); | 28 | bool sound = AudioManager::self()->isWorking(); |
| 29 | bool muted = !(sound && m_settings->value("muted", false).toBool()); | 29 | bool muted = !sound || m_settings->value("muted", false).toBool(); |
| 30 | AudioManager::self()->setMuted(muted); | 30 | AudioManager::self()->setMuted(muted); |
| 31 | 31 | ||
| 32 | QImage img(muted ? ":/soundoff" : ":/soundon"); | 32 | QImage img(muted ? ":/soundoff" : ":/soundon"); |
diff --git a/pacman-c++/mainwidget.cpp b/pacman-c++/mainwidget.cpp index ebd0f02..f5d4b7f 100644 --- a/pacman-c++/mainwidget.cpp +++ b/pacman-c++/mainwidget.cpp | |||
| @@ -10,26 +10,27 @@ MainWidget::MainWidget(QWidget *parent) | |||
| 10 | : SceneHolder(parent), m_currentKey(0), m_running(false) | 10 | : SceneHolder(parent), m_currentKey(0), m_running(false) |
| 11 | { | 11 | { |
| 12 | createGui(); | 12 | createGui(); |
| 13 | updateMap(Util::createDummyMap()); | 13 | updateMap(Util::createDemoMap()); |
| 14 | |||
| 15 | //connect(AudioPlayer::self(), SIGNAL(finished()), this, SLOT(startGame())); | ||
| 16 | //AudioPlayer::self()->play(AudioPlayer::Intro); | ||
| 17 | 14 | ||
| 18 | Color::Color myColor = connectToServer(); | 15 | Color::Color myColor = connectToServer(); |
| 19 | if (myColor == Color::none) { | 16 | if (myColor == Color::none) |
| 17 | { | ||
| 20 | QMessageBox::critical(this, "Error", "Failed to connect to server, falling back to local test mode"); | 18 | QMessageBox::critical(this, "Error", "Failed to connect to server, falling back to local test mode"); |
| 21 | // TODO: quit application here or sth | 19 | // TODO: quit application here or sth |
| 22 | m_socket = NULL; | 20 | m_socket = NULL; |
| 23 | QTimer *timer = new QTimer(this); | 21 | QTimer *timer = new QTimer(this); |
| 24 | connect(timer, SIGNAL(timeout()), this, SLOT(tick())); | 22 | connect(timer, SIGNAL(timeout()), this, SLOT(tick())); |
| 25 | timer->start(Constants::tick); | 23 | timer->start(Constants::tick); |
| 26 | } else { | ||
| 27 | connect(m_socket, SIGNAL(readyRead()), this, SLOT(tick())); | ||
| 28 | } | 24 | } |
| 25 | else | ||
| 26 | connect(m_socket, SIGNAL(readyRead()), this, SLOT(tick())); | ||
| 29 | 27 | ||
| 30 | // TODO: use mycolor | 28 | // TODO: use mycolor |
| 31 | qDebug() << "myc" << myColor; | 29 | qDebug() << "mycolor=" << myColor; |
| 32 | 30 | ||
| 31 | //TODO: play intro as soon as there are enough players | ||
| 32 | //connect(AudioPlayer::self(), SIGNAL(finished()), this, SLOT(startGame())); | ||
| 33 | //AudioPlayer::self()->play(AudioPlayer::Intro); | ||
| 33 | startGame(); | 34 | startGame(); |
| 34 | } | 35 | } |
| 35 | 36 | ||
| @@ -82,6 +83,7 @@ void MainWidget::updateScore(const ProtoBuf::MapUpdate& packet) | |||
| 82 | QLabel *turnPointsLbl; | 83 | QLabel *turnPointsLbl; |
| 83 | QLabel *allPointsLbl; | 84 | QLabel *allPointsLbl; |
| 84 | 85 | ||
| 86 | //TODO: change proto and move that inside an array | ||
| 85 | turnPointsLbl = dynamic_cast<QLabel*>(m_playerScoreLayouts.at(0)->itemAtPosition(0,1)->widget()); | 87 | turnPointsLbl = dynamic_cast<QLabel*>(m_playerScoreLayouts.at(0)->itemAtPosition(0,1)->widget()); |
| 86 | allPointsLbl = dynamic_cast<QLabel*>(m_playerScoreLayouts.at(0)->itemAtPosition(1,1)->widget()); | 88 | allPointsLbl = dynamic_cast<QLabel*>(m_playerScoreLayouts.at(0)->itemAtPosition(1,1)->widget()); |
| 87 | turnPointsLbl->setText(QString::number(packet.round_points_red())); | 89 | turnPointsLbl->setText(QString::number(packet.round_points_red())); |
| @@ -98,7 +100,7 @@ void MainWidget::updateScore(const ProtoBuf::MapUpdate& packet) | |||
| 98 | allPointsLbl->setText(QString::number(packet.game_points_green())); | 100 | allPointsLbl->setText(QString::number(packet.game_points_green())); |
| 99 | } | 101 | } |
| 100 | 102 | ||
| 101 | Transmission::field_t MainWidget::translateKey(int key, int def) | 103 | Transmission::field_t MainWidget::translateKey(int key) |
| 102 | { | 104 | { |
| 103 | switch(key) | 105 | switch(key) |
| 104 | { | 106 | { |
| @@ -119,16 +121,16 @@ Transmission::field_t MainWidget::translateKey(int key, int def) | |||
| 119 | return Transmission::direction_right; | 121 | return Transmission::direction_right; |
| 120 | break; | 122 | break; |
| 121 | default: | 123 | default: |
| 122 | return def; | 124 | return Transmission::direction_none; |
| 123 | } | 125 | } |
| 124 | } | 126 | } |
| 125 | 127 | ||
| 126 | void MainWidget::tick() | 128 | void MainWidget::tick() |
| 127 | { | 129 | { |
| 128 | if (m_socket == NULL) { | 130 | if (m_socket == NULL) |
| 131 | { | ||
| 129 | // OLD TEST MODE | 132 | // OLD TEST MODE |
| 130 | Actor::Movement mov = Util::transmissionMovementToActor(m_currentKey, Actor::None); | 133 | Actor::Movement mov = Util::transmissionMovementToActor(m_currentKey, Actor::None); |
| 131 | |||
| 132 | QMapIterator<Color::Color, Actor*> i(m_actors); | 134 | QMapIterator<Color::Color, Actor*> i(m_actors); |
| 133 | while (i.hasNext()) | 135 | while (i.hasNext()) |
| 134 | { | 136 | { |
| @@ -142,7 +144,9 @@ void MainWidget::tick() | |||
| 142 | list.at(j)->setOpacity(0.6); | 144 | list.at(j)->setOpacity(0.6); |
| 143 | } | 145 | } |
| 144 | } | 146 | } |
| 145 | } else { | 147 | } |
| 148 | else | ||
| 149 | { | ||
| 146 | std::string dataStr; | 150 | std::string dataStr; |
| 147 | Util::QByteArrayToStdString(m_socket->readAll(), dataStr); | 151 | Util::QByteArrayToStdString(m_socket->readAll(), dataStr); |
| 148 | 152 | ||
| @@ -152,8 +156,10 @@ void MainWidget::tick() | |||
| 152 | Transmission::map_t map = Util::createUninitialisedMap(); | 156 | Transmission::map_t map = Util::createUninitialisedMap(); |
| 153 | Q_ASSERT(packet.field_size() == (int) (Constants::map_size.width * Constants::map_size.height)); | 157 | Q_ASSERT(packet.field_size() == (int) (Constants::map_size.width * Constants::map_size.height)); |
| 154 | int i = 0; | 158 | int i = 0; |
| 155 | for (unsigned int x = 0; x < Constants::map_size.width; ++x) { | 159 | for (unsigned int x = 0; x < Constants::map_size.width; ++x) |
| 156 | for (unsigned int y = 0; y < Constants::map_size.height; ++y) { | 160 | { |
| 161 | for (unsigned int y = 0; y < Constants::map_size.height; ++y) | ||
| 162 | { | ||
| 157 | map[x][y] = packet.field(i); | 163 | map[x][y] = packet.field(i); |
| 158 | ++i; | 164 | ++i; |
| 159 | } | 165 | } |
| @@ -169,23 +175,23 @@ void MainWidget::keyPressEvent(QKeyEvent* event) | |||
| 169 | return; | 175 | return; |
| 170 | 176 | ||
| 171 | QWidget::keyPressEvent(event); | 177 | QWidget::keyPressEvent(event); |
| 172 | Transmission::field_t newKey = translateKey(event->key(), -1); | 178 | Transmission::field_t newKey = translateKey(event->key()); |
| 173 | if (m_currentKey == newKey || newKey == -1) { | 179 | if (m_currentKey == newKey || newKey == Transmission::direction_none) |
| 174 | return; | 180 | return; |
| 175 | } | ||
| 176 | m_currentKey = newKey; | 181 | m_currentKey = newKey; |
| 177 | 182 | ||
| 178 | if (m_socket != NULL) { | 183 | if (m_socket != NULL) |
| 184 | { | ||
| 179 | // send to server | 185 | // send to server |
| 180 | ProtoBuf::KeyPressUpdate packet; | 186 | ProtoBuf::KeyPressUpdate packet; |
| 181 | packet.set_newkey(m_currentKey); | 187 | packet.set_newkey(m_currentKey); |
| 182 | Util::sendPacket(packet, m_socket); | 188 | Util::sendPacket(packet, m_socket); |
| 183 | qDebug() << "send key: " << m_currentKey; | 189 | qDebug() << "send key: " << m_currentKey; |
| 184 | } else { | 190 | } |
| 185 | 191 | else | |
| 192 | { | ||
| 186 | // test stuff | 193 | // test stuff |
| 187 | Actor::Movement mov = Util::transmissionMovementToActor(m_currentKey, Actor::None); | 194 | Actor::Movement mov = Util::transmissionMovementToActor(m_currentKey, Actor::None); |
| 188 | |||
| 189 | QMapIterator<Color::Color, Actor*> i(m_actors); | 195 | QMapIterator<Color::Color, Actor*> i(m_actors); |
| 190 | while (i.hasNext()) | 196 | while (i.hasNext()) |
| 191 | { | 197 | { |
| @@ -229,11 +235,13 @@ Color::Color MainWidget::connectToServer() | |||
| 229 | m_socket = new QTcpSocket(this); | 235 | m_socket = new QTcpSocket(this); |
| 230 | m_socket->connectToHost("127.0.0.1", Constants::port); | 236 | m_socket->connectToHost("127.0.0.1", Constants::port); |
| 231 | bool worked = m_socket->waitForConnected(Constants::connection_timeout); | 237 | bool worked = m_socket->waitForConnected(Constants::connection_timeout); |
| 232 | if (worked) { | 238 | if (worked) |
| 239 | { | ||
| 233 | // additional init | 240 | // additional init |
| 234 | // first packet is our color | 241 | // first packet is our color |
| 235 | worked = m_socket->waitForReadyRead(); | 242 | worked = m_socket->waitForReadyRead(); |
| 236 | if (worked) { | 243 | if (worked) |
| 244 | { | ||
| 237 | std::string data; | 245 | std::string data; |
| 238 | Util::QByteArrayToStdString(m_socket->readAll(), data); | 246 | Util::QByteArrayToStdString(m_socket->readAll(), data); |
| 239 | ProtoBuf::WhoAmI packet; | 247 | ProtoBuf::WhoAmI packet; |
| @@ -243,4 +251,3 @@ Color::Color MainWidget::connectToServer() | |||
| 243 | } | 251 | } |
| 244 | return Color::none; | 252 | return Color::none; |
| 245 | } | 253 | } |
| 246 | |||
diff --git a/pacman-c++/mainwidget.h b/pacman-c++/mainwidget.h index bd83d5f..ede3ecf 100644 --- a/pacman-c++/mainwidget.h +++ b/pacman-c++/mainwidget.h | |||
| @@ -43,7 +43,7 @@ private: | |||
| 43 | Transmission::field_t m_currentKey; | 43 | Transmission::field_t m_currentKey; |
| 44 | 44 | ||
| 45 | // translate Qt::Key to our key format | 45 | // translate Qt::Key to our key format |
| 46 | Transmission::field_t translateKey(int key, int def=0); | 46 | Transmission::field_t translateKey(int key); |
| 47 | 47 | ||
| 48 | // game running | 48 | // game running |
| 49 | bool m_running; | 49 | bool m_running; |
diff --git a/pacman-c++/pacman.proto b/pacman-c++/pacman.proto index 129d07f..3a09702 100644 --- a/pacman-c++/pacman.proto +++ b/pacman-c++/pacman.proto | |||
| @@ -4,6 +4,7 @@ message KeyPressUpdate { | |||
| 4 | required uint32 newKey = 1; | 4 | required uint32 newKey = 1; |
| 5 | } | 5 | } |
| 6 | 6 | ||
| 7 | //TODO move points inside array | ||
| 7 | message MapUpdate { | 8 | message MapUpdate { |
| 8 | repeated uint32 field = 1 [packed=true]; | 9 | repeated uint32 field = 1 [packed=true]; |
| 9 | required uint32 round_points_red = 2; | 10 | required uint32 round_points_red = 2; |
diff --git a/pacman-c++/pixmapitem.h b/pacman-c++/pixmapitem.h index cff976f..f57c22a 100644 --- a/pacman-c++/pixmapitem.h +++ b/pacman-c++/pixmapitem.h | |||
| @@ -13,7 +13,9 @@ public: | |||
| 13 | PixmapItem(const QString &fileName, QGraphicsScene *scene); | 13 | PixmapItem(const QString &fileName, QGraphicsScene *scene); |
| 14 | PixmapItem(const QPixmap &pix, QGraphicsItem *parent = 0); | 14 | PixmapItem(const QPixmap &pix, QGraphicsItem *parent = 0); |
| 15 | PixmapItem(const QPixmap &pix, QGraphicsScene *scene); | 15 | PixmapItem(const QPixmap &pix, QGraphicsScene *scene); |
| 16 | virtual ~PixmapItem() {}; | 16 | virtual ~PixmapItem() |
| 17 | {}; | ||
| 18 | |||
| 17 | void setPixmap(const QPixmap &pix); | 19 | void setPixmap(const QPixmap &pix); |
| 18 | void setSprite(int x, int y, int width, int height); | 20 | void setSprite(int x, int y, int width, int height); |
| 19 | QSizeF size() const; | 21 | QSizeF size() const; |
diff --git a/pacman-c++/point.h b/pacman-c++/point.h index 1b5863a..ad1cf77 100644 --- a/pacman-c++/point.h +++ b/pacman-c++/point.h | |||
| @@ -8,7 +8,8 @@ class Point | |||
| 8 | { | 8 | { |
| 9 | public: | 9 | public: |
| 10 | Point(QGraphicsItem *parent=0); | 10 | Point(QGraphicsItem *parent=0); |
| 11 | virtual ~Point() {}; | 11 | virtual ~Point() |
| 12 | {}; | ||
| 12 | }; | 13 | }; |
| 13 | 14 | ||
| 14 | #endif // POINT_H | 15 | #endif // POINT_H |
diff --git a/pacman-c++/sceneholder.cpp b/pacman-c++/sceneholder.cpp index 515d5ec..0236470 100644 --- a/pacman-c++/sceneholder.cpp +++ b/pacman-c++/sceneholder.cpp | |||
| @@ -14,9 +14,8 @@ SceneHolder::SceneHolder(QWidget* parent): QWidget(parent) | |||
| 14 | m_scene->setBackgroundBrush(Qt::black); | 14 | m_scene->setBackgroundBrush(Qt::black); |
| 15 | 15 | ||
| 16 | visualMap.resize(Constants::map_size.width); | 16 | visualMap.resize(Constants::map_size.width); |
| 17 | for (int i=0; i<visualMap.size(); ++i) { | 17 | for (int i = 0; i < visualMap.size(); ++i) |
| 18 | visualMap[i].resize(Constants::map_size.height); | 18 | visualMap[i].resize(Constants::map_size.height); |
| 19 | } | ||
| 20 | } | 19 | } |
| 21 | 20 | ||
| 22 | void SceneHolder::updateMap(const Transmission::map_t& map) | 21 | void SceneHolder::updateMap(const Transmission::map_t& map) |
| @@ -34,16 +33,22 @@ void SceneHolder::updateMap(const Transmission::map_t& map) | |||
| 34 | //qDebug() << "col=" << color; | 33 | //qDebug() << "col=" << color; |
| 35 | 34 | ||
| 36 | PixmapItem* item = NULL; | 35 | PixmapItem* item = NULL; |
| 37 | if (cur == Transmission::none) { // no update | 36 | if (cur == Transmission::none) |
| 38 | } else if (cur & Transmission::empty) { | 37 | { |
| 38 | // no update | ||
| 39 | } | ||
| 40 | else if (cur & Transmission::empty) | ||
| 41 | { | ||
| 39 | PixmapItem* oldItem = visualMap[x][y]; | 42 | PixmapItem* oldItem = visualMap[x][y]; |
| 40 | // remove elements (in case it's not an actor) | 43 | // remove elements (in case it's not an actor) |
| 41 | if (oldItem != NULL && dynamic_cast<Actor*>(item) == 0) { | 44 | if (oldItem != NULL && dynamic_cast<Actor*>(item) == NULL) |
| 45 | { | ||
| 42 | m_scene->removeItem(oldItem); | 46 | m_scene->removeItem(oldItem); |
| 43 | visualMap[x][y] = NULL; | 47 | visualMap[x][y] = NULL; |
| 44 | delete oldItem; | 48 | delete oldItem; |
| 45 | } | 49 | } |
| 46 | } else if (cur & Transmission::block) | 50 | } |
| 51 | else if (cur & Transmission::block) | ||
| 47 | { | 52 | { |
| 48 | unsigned int neighbours = Block::None; | 53 | unsigned int neighbours = Block::None; |
| 49 | // check left side | 54 | // check left side |
| @@ -81,7 +86,8 @@ void SceneHolder::updateMap(const Transmission::map_t& map) | |||
| 81 | actor->move(direction); | 86 | actor->move(direction); |
| 82 | qDebug() << "actor move " << direction; | 87 | qDebug() << "actor move " << direction; |
| 83 | } | 88 | } |
| 84 | else { | 89 | else |
| 90 | { | ||
| 85 | qDebug() << "abort at " << cur; | 91 | qDebug() << "abort at " << cur; |
| 86 | Q_ASSERT(false); | 92 | Q_ASSERT(false); |
| 87 | } | 93 | } |
| @@ -108,9 +114,18 @@ QPoint SceneHolder::mapPositionToCoord(unsigned int x, unsigned int y) | |||
| 108 | return QPoint(x * Constants::field_size.width, y * Constants::field_size.height); | 114 | return QPoint(x * Constants::field_size.width, y * Constants::field_size.height); |
| 109 | } | 115 | } |
| 110 | 116 | ||
| 117 | QPoint SceneHolder::mapPositionToCoord(QPoint point) | ||
| 118 | { | ||
| 119 | return mapPositionToCoord(point.x(), point.y()); | ||
| 120 | } | ||
| 121 | |||
| 111 | QPoint SceneHolder::CoordToMapPosition(unsigned int x, unsigned int y) | 122 | QPoint SceneHolder::CoordToMapPosition(unsigned int x, unsigned int y) |
| 112 | { | 123 | { |
| 113 | return QPoint(x / Constants::field_size.width, y / Constants::field_size.height); | 124 | return QPoint(x / Constants::field_size.width, y / Constants::field_size.height); |
| 114 | } | 125 | } |
| 115 | 126 | ||
| 127 | QPoint SceneHolder::CoordToMapPosition(QPoint point) | ||
| 128 | { | ||
| 129 | return CoordToMapPosition(point.x(), point.y()); | ||
| 130 | } | ||
| 116 | 131 | ||
diff --git a/pacman-c++/sceneholder.h b/pacman-c++/sceneholder.h index f188956..7494c3f 100644 --- a/pacman-c++/sceneholder.h +++ b/pacman-c++/sceneholder.h | |||
| @@ -15,15 +15,17 @@ class SceneHolder | |||
| 15 | 15 | ||
| 16 | public: | 16 | public: |
| 17 | SceneHolder(QWidget* parent = 0); | 17 | SceneHolder(QWidget* parent = 0); |
| 18 | virtual ~SceneHolder() {}; | 18 | virtual ~SceneHolder() |
| 19 | {}; | ||
| 19 | 20 | ||
| 20 | protected: | 21 | protected: |
| 21 | |||
| 22 | virtual void updateMap(const Transmission::map_t& map); | 22 | virtual void updateMap(const Transmission::map_t& map); |
| 23 | 23 | ||
| 24 | // data conversion | 24 | // data conversion |
| 25 | QPoint mapPositionToCoord(unsigned int x, unsigned int y); | 25 | QPoint mapPositionToCoord(unsigned int x, unsigned int y); |
| 26 | QPoint mapPositionToCoord(QPoint point); | ||
| 26 | QPoint CoordToMapPosition(unsigned int x, unsigned int y); | 27 | QPoint CoordToMapPosition(unsigned int x, unsigned int y); |
| 28 | QPoint CoordToMapPosition(QPoint point); | ||
| 27 | 29 | ||
| 28 | // map of all pixmap instances | 30 | // map of all pixmap instances |
| 29 | QVector< QVector<PixmapItem *> > visualMap; | 31 | QVector< QVector<PixmapItem *> > visualMap; |
| @@ -32,7 +34,6 @@ protected: | |||
| 32 | QMap<Color::Color, Actor*> m_actors; | 34 | QMap<Color::Color, Actor*> m_actors; |
| 33 | 35 | ||
| 34 | QGraphicsScene *m_scene; | 36 | QGraphicsScene *m_scene; |
| 35 | |||
| 36 | }; | 37 | }; |
| 37 | 38 | ||
| 38 | #endif // SCENEHOLDER_H | 39 | #endif // SCENEHOLDER_H |
diff --git a/pacman-c++/server.cpp b/pacman-c++/server.cpp index c83c70d..144043b 100644 --- a/pacman-c++/server.cpp +++ b/pacman-c++/server.cpp | |||
| @@ -13,7 +13,7 @@ Server::Server(QWidget *parent) | |||
| 13 | waitForClientConnections(); | 13 | waitForClientConnections(); |
| 14 | qDebug() << "clients connected"; | 14 | qDebug() << "clients connected"; |
| 15 | 15 | ||
| 16 | updateMap(Util::createDummyMap()); | 16 | updateMap(Util::createDemoMap()); |
| 17 | 17 | ||
| 18 | QTimer *timer = new QTimer(this); | 18 | QTimer *timer = new QTimer(this); |
| 19 | connect(timer, SIGNAL(timeout()), this, SLOT(tick())); | 19 | connect(timer, SIGNAL(timeout()), this, SLOT(tick())); |
| @@ -35,33 +35,51 @@ Transmission::map_t Server::calculateUpdates() | |||
| 35 | Transmission::map_t map = Util::createEmptyMap(); | 35 | Transmission::map_t map = Util::createEmptyMap(); |
| 36 | 36 | ||
| 37 | QMapIterator<Color::Color, Actor::Movement> i(m_actorMovements); | 37 | QMapIterator<Color::Color, Actor::Movement> i(m_actorMovements); |
| 38 | while (i.hasNext()) { | 38 | while (i.hasNext()) |
| 39 | { | ||
| 39 | i.next(); | 40 | i.next(); |
| 40 | Actor *actor = m_actors.value( i.key() ); | 41 | Actor *actor = m_actors.value(i.key()); |
| 41 | QPoint mapPosition = CoordToMapPosition(actor->x(), actor->y()); | 42 | QPoint mapPosition = actor->pos().toPoint(); |
| 43 | mapPosition = CoordToMapPosition(actor->pos().toPoint()); | ||
| 42 | qDebug() << "actor " << i.key() << " is at " << mapPosition; | 44 | qDebug() << "actor " << i.key() << " is at " << mapPosition; |
| 43 | 45 | ||
| 44 | QPoint newMapPosition = mapPosition; | 46 | QPoint newMapPosition = mapPosition; |
| 45 | switch (i.value()) { | 47 | switch (i.value()) |
| 46 | case Actor::Up: newMapPosition += QPoint(0, -1); break; | 48 | { |
| 47 | case Actor::Down: newMapPosition += QPoint(0, 1); break; | 49 | case Actor::Up: |
| 48 | case Actor::Left: newMapPosition += QPoint(-1, 0); break; | 50 | newMapPosition += QPoint(0, -1); |
| 49 | case Actor::Right: newMapPosition += QPoint(1, 0); break; | 51 | break; |
| 50 | case Actor::None: break; | 52 | case Actor::Down: |
| 51 | default: Q_ASSERT(false); | 53 | newMapPosition += QPoint(0, 1); |
| 54 | break; | ||
| 55 | case Actor::Left: | ||
| 56 | newMapPosition += QPoint(-1, 0); | ||
| 57 | break; | ||
| 58 | case Actor::Right: | ||
| 59 | newMapPosition += QPoint(1, 0); | ||
| 60 | break; | ||
| 61 | case Actor::None: | ||
| 62 | break; | ||
| 63 | default: | ||
| 64 | Q_ASSERT(false); | ||
| 52 | } | 65 | } |
| 53 | if (newMapPosition.x() < 0) newMapPosition.setX(0); | 66 | |
| 54 | if (newMapPosition.x() >= visualMap.size()) newMapPosition.setX(visualMap.size()-1); | 67 | if (newMapPosition.x() < 0) |
| 55 | if (newMapPosition.y() < 0) newMapPosition.setY(0); | 68 | newMapPosition.setX(0); |
| 56 | if (newMapPosition.y() >= visualMap[newMapPosition.x()].size()) newMapPosition.setY(visualMap[newMapPosition.x()].size()-1); | 69 | if (newMapPosition.x() >= visualMap.size()) |
| 70 | newMapPosition.setX(visualMap.size() - 1); | ||
| 71 | if (newMapPosition.y() < 0) | ||
| 72 | newMapPosition.setY(0); | ||
| 73 | if (newMapPosition.y() >= visualMap[newMapPosition.x()].size()) | ||
| 74 | newMapPosition.setY(visualMap[newMapPosition.x()].size() - 1); | ||
| 57 | 75 | ||
| 58 | // <t3h g4m3 10gic> | 76 | // <t3h g4m3 10gic> |
| 59 | if(dynamic_cast<Block*>(visualMap[newMapPosition.x()][newMapPosition.y()]) != 0) { | 77 | if(dynamic_cast<Block*>(visualMap[newMapPosition.x()][newMapPosition.y()]) != 0) |
| 60 | continue; | 78 | continue; |
| 61 | } | ||
| 62 | // </t3h g4m2 10gic> | 79 | // </t3h g4m2 10gic> |
| 63 | 80 | ||
| 64 | if (mapPosition != newMapPosition) { | 81 | if (mapPosition != newMapPosition) |
| 82 | { | ||
| 65 | map[mapPosition.x()][mapPosition.y()] = Transmission::empty; | 83 | map[mapPosition.x()][mapPosition.y()] = Transmission::empty; |
| 66 | map[newMapPosition.x()][newMapPosition.y()] = | 84 | map[newMapPosition.x()][newMapPosition.y()] = |
| 67 | Transmission::pacman | i.key() | | 85 | Transmission::pacman | i.key() | |
| @@ -76,10 +94,10 @@ QSharedPointer< ProtoBuf::MapUpdate > Server::createUpdatePacket(Transmission::m | |||
| 76 | QSharedPointer<ProtoBuf::MapUpdate> updatePacket = | 94 | QSharedPointer<ProtoBuf::MapUpdate> updatePacket = |
| 77 | QSharedPointer<ProtoBuf::MapUpdate>(new ProtoBuf::MapUpdate); | 95 | QSharedPointer<ProtoBuf::MapUpdate>(new ProtoBuf::MapUpdate); |
| 78 | 96 | ||
| 79 | for (unsigned int x = 0; x < Constants::map_size.width; ++x) { | 97 | for (unsigned int x = 0; x < Constants::map_size.width; ++x) |
| 80 | for (unsigned int y = 0; y < Constants::map_size.height; ++y) { | 98 | { |
| 99 | for (unsigned int y = 0; y < Constants::map_size.height; ++y) | ||
| 81 | updatePacket->add_field(map[x][y]); | 100 | updatePacket->add_field(map[x][y]); |
| 82 | } | ||
| 83 | } | 101 | } |
| 84 | updatePacket->set_round_points_red(m_actors.value(Color::red)->getRoundPoints()); | 102 | updatePacket->set_round_points_red(m_actors.value(Color::red)->getRoundPoints()); |
| 85 | updatePacket->set_game_points_red(m_actors.value(Color::red)->getGamePoints()); | 103 | updatePacket->set_game_points_red(m_actors.value(Color::red)->getGamePoints()); |
| @@ -101,9 +119,11 @@ void Server::waitForClientConnections() | |||
| 101 | 119 | ||
| 102 | Color::Color playerColors[3] = { Color::red, Color::blue, Color::green }; | 120 | Color::Color playerColors[3] = { Color::red, Color::blue, Color::green }; |
| 103 | #ifdef SINGLE | 121 | #ifdef SINGLE |
| 104 | for (unsigned int i=0; i<1; ++i) { | 122 | for (unsigned int i=0; i < 1; ++i) |
| 123 | { | ||
| 105 | #else | 124 | #else |
| 106 | for (unsigned int i=0; i<Color::max; ++i) { | 125 | for (unsigned int i=0; i < Color::max; ++i) |
| 126 | { | ||
| 107 | #endif | 127 | #endif |
| 108 | bool connectionAvailable = tcpSrv->waitForNewConnection(-1); | 128 | bool connectionAvailable = tcpSrv->waitForNewConnection(-1); |
| 109 | Q_ASSERT(connectionAvailable); | 129 | Q_ASSERT(connectionAvailable); |
| @@ -124,21 +144,22 @@ void Server::sendUpdate(QSharedPointer< ProtoBuf::MapUpdate > packet) | |||
| 124 | { | 144 | { |
| 125 | std::string dataStr = packet->SerializeAsString(); | 145 | std::string dataStr = packet->SerializeAsString(); |
| 126 | const char *data = dataStr.c_str(); | 146 | const char *data = dataStr.c_str(); |
| 127 | foreach(QTcpSocket *socket, m_clientConnections) { | 147 | foreach(QTcpSocket *socket, m_clientConnections) |
| 128 | Util::sendPacket(data, dataStr.length(), socket); | 148 | Util::sendPacket(data, dataStr.length(), socket); |
| 129 | } | ||
| 130 | } | 149 | } |
| 131 | 150 | ||
| 132 | void Server::keyPressUpdate() | 151 | void Server::keyPressUpdate() |
| 133 | { | 152 | { |
| 134 | qDebug() << "kpress"; | 153 | qDebug() << "kpress"; |
| 135 | QMapIterator<Color::Color, QTcpSocket*> i(m_clientConnections); | 154 | QMapIterator<Color::Color, QTcpSocket*> i(m_clientConnections); |
| 136 | while (i.hasNext()) { | 155 | while (i.hasNext()) |
| 156 | { | ||
| 137 | i.next(); | 157 | i.next(); |
| 138 | Color::Color color = i.key(); | 158 | Color::Color color = i.key(); |
| 139 | QTcpSocket *socket = i.value(); | 159 | QTcpSocket *socket = i.value(); |
| 140 | qDebug() << "data?"; | 160 | qDebug() << "data?"; |
| 141 | if (socket->bytesAvailable() > 0) { | 161 | if (socket->bytesAvailable() > 0) |
| 162 | { | ||
| 142 | qDebug() << "data!"; | 163 | qDebug() << "data!"; |
| 143 | std::string dataStr; | 164 | std::string dataStr; |
| 144 | Util::QByteArrayToStdString(socket->readAll(), dataStr); | 165 | Util::QByteArrayToStdString(socket->readAll(), dataStr); |
| @@ -146,7 +167,7 @@ void Server::keyPressUpdate() | |||
| 146 | packet.ParseFromString(dataStr); | 167 | packet.ParseFromString(dataStr); |
| 147 | Transmission::field_t direction = packet.newkey(); | 168 | Transmission::field_t direction = packet.newkey(); |
| 148 | qDebug() << "data:" << direction; | 169 | qDebug() << "data:" << direction; |
| 149 | m_actorMovements[ color ] = Util::transmissionMovementToActor(direction); | 170 | m_actorMovements[color] = Util::transmissionMovementToActor(direction); |
| 150 | } | 171 | } |
| 151 | } | 172 | } |
| 152 | } | 173 | } |
diff --git a/pacman-c++/util.cpp b/pacman-c++/util.cpp index 23826f7..3d04d9f 100644 --- a/pacman-c++/util.cpp +++ b/pacman-c++/util.cpp | |||
| @@ -2,9 +2,10 @@ | |||
| 2 | 2 | ||
| 3 | #include <QtNetwork/QTcpSocket> | 3 | #include <QtNetwork/QTcpSocket> |
| 4 | 4 | ||
| 5 | namespace Util { | 5 | namespace Util |
| 6 | 6 | { | |
| 7 | Transmission::map_t createUninitialisedMap() { | 7 | Transmission::map_t createUninitialisedMap() |
| 8 | { | ||
| 8 | Transmission::map_t map; | 9 | Transmission::map_t map; |
| 9 | map = new Transmission::field_t*[Constants::map_size.width]; | 10 | map = new Transmission::field_t*[Constants::map_size.width]; |
| 10 | for (unsigned int i = 0; i < Constants::map_size.width; ++i) | 11 | for (unsigned int i = 0; i < Constants::map_size.width; ++i) |
| @@ -12,7 +13,8 @@ namespace Util { | |||
| 12 | return map; | 13 | return map; |
| 13 | } | 14 | } |
| 14 | 15 | ||
| 15 | Transmission::map_t createEmptyMap() { | 16 | Transmission::map_t createEmptyMap() |
| 17 | { | ||
| 16 | Transmission::map_t map = createUninitialisedMap(); | 18 | Transmission::map_t map = createUninitialisedMap(); |
| 17 | for (unsigned int x = 0; x < Constants::map_size.width; ++x) | 19 | for (unsigned int x = 0; x < Constants::map_size.width; ++x) |
| 18 | { | 20 | { |
| @@ -24,8 +26,9 @@ namespace Util { | |||
| 24 | } | 26 | } |
| 25 | return map; | 27 | return map; |
| 26 | } | 28 | } |
| 29 | |||
| 27 | // temporary | 30 | // temporary |
| 28 | Transmission::map_t createDummyMap() | 31 | Transmission::map_t createDemoMap() |
| 29 | { | 32 | { |
| 30 | Transmission::map_t map = createEmptyMap(); | 33 | Transmission::map_t map = createEmptyMap(); |
| 31 | 34 | ||
| @@ -86,9 +89,10 @@ namespace Util { | |||
| 86 | return map; | 89 | return map; |
| 87 | } | 90 | } |
| 88 | 91 | ||
| 89 | 92 | Transmission::field_t actorMovementToTransmission(Actor::Movement mov, Transmission::field_t def) | |
| 90 | Transmission::field_t actorMovementToTransmission(Actor::Movement mov, Transmission::field_t def) { | 93 | { |
| 91 | switch (mov) { | 94 | switch (mov) |
| 95 | { | ||
| 92 | case Actor::None: | 96 | case Actor::None: |
| 93 | return Transmission::direction_none; | 97 | return Transmission::direction_none; |
| 94 | break; | 98 | break; |
| @@ -105,17 +109,18 @@ namespace Util { | |||
| 105 | return Transmission::direction_down; | 109 | return Transmission::direction_down; |
| 106 | break; | 110 | break; |
| 107 | default: | 111 | default: |
| 108 | if (def == static_cast<Transmission::field_t>(-1)) { | 112 | if (def == static_cast<Transmission::field_t>(-1)) |
| 109 | Q_ASSERT(false); | 113 | Q_ASSERT(false); |
| 110 | } else { | 114 | else |
| 111 | return def; | 115 | return def; |
| 112 | } | ||
| 113 | } | 116 | } |
| 114 | return 0; // for pleasing the compiler | 117 | return 0; // for pleasing the compiler |
| 115 | } | 118 | } |
| 116 | 119 | ||
| 117 | Actor::Movement transmissionMovementToActor(Transmission::field_t field, Actor::Movement def) { | 120 | Actor::Movement transmissionMovementToActor(Transmission::field_t field, Actor::Movement def) |
| 118 | switch (field) { | 121 | { |
| 122 | switch (field) | ||
| 123 | { | ||
| 119 | case Transmission::direction_none: | 124 | case Transmission::direction_none: |
| 120 | return Actor::None; | 125 | return Actor::None; |
| 121 | break; | 126 | break; |
| @@ -132,39 +137,40 @@ namespace Util { | |||
| 132 | return Actor::Down; | 137 | return Actor::Down; |
| 133 | break; | 138 | break; |
| 134 | default: | 139 | default: |
| 135 | if (def == Actor::Movement(-1)) { | 140 | if (def == Actor::Movement(-1)) |
| 136 | Q_ASSERT(false); | 141 | Q_ASSERT(false); |
| 137 | } else { | 142 | else |
| 138 | return def; | 143 | return def; |
| 139 | } | ||
| 140 | } | 144 | } |
| 141 | return Actor::None; // for pleasing the compiler | 145 | return Actor::None; // for pleasing the compiler |
| 142 | } | 146 | } |
| 143 | 147 | ||
| 144 | void QByteArrayToStdString(const QByteArray& arr, std::string& str) { | 148 | void QByteArrayToStdString(const QByteArray& arr, std::string& str) |
| 149 | { | ||
| 145 | // TODO: normal conversion to std::string won't work, | 150 | // TODO: normal conversion to std::string won't work, |
| 146 | // probably due to \0-bytes. | 151 | // probably due to \0-bytes. |
| 147 | //std::string dataStr = std::string(data.constData()); | 152 | //std::string dataStr = std::string(data.constData()); |
| 148 | //std::string dataStr = QString(data).toStdString(); | 153 | //std::string dataStr = QString(data).toStdString(); |
| 149 | for (int i=0; i<arr.size(); ++i) { | 154 | for (int i=0; i<arr.size(); ++i) |
| 150 | str += arr[i]; | 155 | str += arr[i]; |
| 151 | } | ||
| 152 | } | 156 | } |
| 153 | 157 | ||
| 154 | void sendPacket(const ::google::protobuf::Message& packet, QTcpSocket *socket) { | 158 | void sendPacket(const ::google::protobuf::Message& packet, QTcpSocket *socket) |
| 159 | { | ||
| 155 | std::string dataStr = packet.SerializeAsString(); | 160 | std::string dataStr = packet.SerializeAsString(); |
| 156 | const char *data = dataStr.c_str(); | 161 | const char *data = dataStr.c_str(); |
| 157 | sendPacket(data, dataStr.length(), socket); | 162 | sendPacket(data, dataStr.length(), socket); |
| 158 | } | 163 | } |
| 159 | 164 | ||
| 160 | void sendPacket(const char *data, unsigned int length, QTcpSocket *socket) { | 165 | void sendPacket(const char *data, unsigned int length, QTcpSocket *socket) |
| 166 | { | ||
| 161 | unsigned int bytesWritten = socket->write(data, length); | 167 | unsigned int bytesWritten = socket->write(data, length); |
| 162 | if (bytesWritten != length) { | 168 | if (bytesWritten != length) |
| 169 | { | ||
| 163 | qDebug() << "written: " << bytesWritten; | 170 | qDebug() << "written: " << bytesWritten; |
| 164 | qDebug() << "strl: " << length; | 171 | qDebug() << "strl: " << length; |
| 165 | } | 172 | } |
| 166 | Q_ASSERT(bytesWritten == length); | 173 | Q_ASSERT(bytesWritten == length); |
| 167 | socket->flush(); | 174 | socket->flush(); |
| 168 | } | 175 | } |
| 169 | |||
| 170 | } | 176 | } |
diff --git a/pacman-c++/util.h b/pacman-c++/util.h index 4c0ccb0..1422dee 100644 --- a/pacman-c++/util.h +++ b/pacman-c++/util.h | |||
| @@ -7,11 +7,10 @@ | |||
| 7 | 7 | ||
| 8 | class QTcpSocket; | 8 | class QTcpSocket; |
| 9 | 9 | ||
| 10 | namespace Util { | 10 | namespace Util |
| 11 | { | ||
| 11 | Transmission::map_t createUninitialisedMap(); | 12 | Transmission::map_t createUninitialisedMap(); |
| 12 | 13 | Transmission::map_t createDemoMap(); | |
| 13 | Transmission::map_t createDummyMap(); | ||
| 14 | |||
| 15 | Transmission::map_t createEmptyMap(); | 14 | Transmission::map_t createEmptyMap(); |
| 16 | 15 | ||
| 17 | // default is to assert false with -1 | 16 | // default is to assert false with -1 |
