diff options
| author | manuel <manuel@mausz.at> | 2011-05-02 17:12:11 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2011-05-02 17:12:11 +0200 |
| commit | 8b13a88127a70da7a4e307df828d65811ae5d0f1 (patch) | |
| tree | d54fca9a1508f1e3a18b4062475663b34e92aabd /pacman-c++ | |
| parent | ce20694e0db010b5d65bdd2ee81a410efbf99e3d (diff) | |
| download | foop-8b13a88127a70da7a4e307df828d65811ae5d0f1.tar.gz foop-8b13a88127a70da7a4e307df828d65811ae5d0f1.tar.bz2 foop-8b13a88127a70da7a4e307df828d65811ae5d0f1.zip | |
smaller output
Diffstat (limited to 'pacman-c++')
| -rw-r--r-- | pacman-c++/actor.cpp | 3 | ||||
| -rw-r--r-- | pacman-c++/audio.cpp | 2 | ||||
| -rw-r--r-- | pacman-c++/pacman.pro | 4 | ||||
| -rw-r--r-- | pacman-c++/pacman.server.pro | 4 | ||||
| -rw-r--r-- | pacman-c++/server.cpp | 37 | ||||
| -rw-r--r-- | pacman-c++/util.cpp | 27 | ||||
| -rw-r--r-- | pacman-c++/util.h | 1 |
7 files changed, 58 insertions, 20 deletions
diff --git a/pacman-c++/actor.cpp b/pacman-c++/actor.cpp index 9c2d2fa..9d22e1b 100644 --- a/pacman-c++/actor.cpp +++ b/pacman-c++/actor.cpp | |||
| @@ -62,12 +62,11 @@ Actor::Actor(Color::Color color, bool local, QGraphicsItem *parent) | |||
| 62 | for (int i = 0; i < 11; i++) | 62 | for (int i = 0; i < 11; i++) |
| 63 | { | 63 | { |
| 64 | PixmapItem *img = new PixmapItem(m_pix, this); | 64 | PixmapItem *img = new PixmapItem(m_pix, this); |
| 65 | img->setZValue(zValue() * 10); | ||
| 66 | m_images.append(img); | 65 | m_images.append(img); |
| 67 | int x = i * Constants::sprite_offset + Constants::sprite_margin; | 66 | int x = i * Constants::sprite_offset + Constants::sprite_margin; |
| 68 | int y = 5 * Constants::sprite_offset + Constants::sprite_margin; | 67 | int y = 5 * Constants::sprite_offset + Constants::sprite_margin; |
| 69 | img->setSprite(x, y, Constants::field_size.width, Constants::field_size.height); | 68 | img->setSprite(x, y, Constants::field_size.width, Constants::field_size.height); |
| 70 | img->setZValue(zValue()); | 69 | img->setZValue(zValue() * 10); |
| 71 | img->setVisible(false); | 70 | img->setVisible(false); |
| 72 | 71 | ||
| 73 | QPropertyAnimation *fadein = new QPropertyAnimation(img, "visible", m_dieing); | 72 | QPropertyAnimation *fadein = new QPropertyAnimation(img, "visible", m_dieing); |
diff --git a/pacman-c++/audio.cpp b/pacman-c++/audio.cpp index 5fb4416..70cd37e 100644 --- a/pacman-c++/audio.cpp +++ b/pacman-c++/audio.cpp | |||
| @@ -260,7 +260,7 @@ void AudioPlayer::stateChanged_ex(Phonon::State newstate, Phonon::State /* oldst | |||
| 260 | void AudioPlayer::testFinished() | 260 | void AudioPlayer::testFinished() |
| 261 | { | 261 | { |
| 262 | if (!m_working) | 262 | if (!m_working) |
| 263 | qDebug() << "There's no sound for you :("; | 263 | qWarning() << "There's no sound for you :("; |
| 264 | disconnect(this, SIGNAL(stateChanged(Phonon::State, Phonon::State)), this, SLOT(stateChanged_ex(Phonon::State, Phonon::State))); | 264 | disconnect(this, SIGNAL(stateChanged(Phonon::State, Phonon::State)), this, SLOT(stateChanged_ex(Phonon::State, Phonon::State))); |
| 265 | } | 265 | } |
| 266 | 266 | ||
diff --git a/pacman-c++/pacman.pro b/pacman-c++/pacman.pro index b5492cd..f5187f9 100644 --- a/pacman-c++/pacman.pro +++ b/pacman-c++/pacman.pro | |||
| @@ -42,3 +42,7 @@ OTHER_FILES += \ | |||
| 42 | PROTOS = pacman.proto | 42 | PROTOS = pacman.proto |
| 43 | include(protobuf.pri) | 43 | include(protobuf.pri) |
| 44 | LIBS += -lprotobuf | 44 | LIBS += -lprotobuf |
| 45 | |||
| 46 | CONFIG(release, debug|release) { | ||
| 47 | DEFINES += QT_NO_DEBUG_OUTPUT | ||
| 48 | } | ||
diff --git a/pacman-c++/pacman.server.pro b/pacman-c++/pacman.server.pro index f42fa62..0b4c568 100644 --- a/pacman-c++/pacman.server.pro +++ b/pacman-c++/pacman.server.pro | |||
| @@ -44,3 +44,7 @@ OTHER_FILES += \ | |||
| 44 | PROTOS = pacman.proto | 44 | PROTOS = pacman.proto |
| 45 | include(protobuf.pri) | 45 | include(protobuf.pri) |
| 46 | LIBS += -lprotobuf | 46 | LIBS += -lprotobuf |
| 47 | |||
| 48 | CONFIG(release, debug|release) { | ||
| 49 | DEFINES += QT_NO_DEBUG_OUTPUT | ||
| 50 | } | ||
diff --git a/pacman-c++/server.cpp b/pacman-c++/server.cpp index 2b43bb9..a7ff89a 100644 --- a/pacman-c++/server.cpp +++ b/pacman-c++/server.cpp | |||
| @@ -30,10 +30,10 @@ bool Server::run() | |||
| 30 | m_tickTimer->setInterval(Constants::tick); | 30 | m_tickTimer->setInterval(Constants::tick); |
| 31 | connect(m_tickTimer, SIGNAL(timeout()), this, SLOT(tick())); | 31 | connect(m_tickTimer, SIGNAL(timeout()), this, SLOT(tick())); |
| 32 | 32 | ||
| 33 | qDebug() << "[Server] Running server..."; | 33 | std::cout << "[Server] Running server..." << std::endl |
| 34 | qDebug() << "[Server] Max players:" << m_maxplayers; | 34 | << "[Server] Max players: " << m_maxplayers << std::endl |
| 35 | qDebug() << "[Server] Number of bots:" << m_numbots; | 35 | << "[Server] Number of bots: " << m_numbots << std::endl |
| 36 | qDebug() << "[Server] Number of rounds:" << m_rounds; | 36 | << "[Server] Number of rounds: " << m_rounds << std::endl; |
| 37 | if (!waitForClientConnections()) | 37 | if (!waitForClientConnections()) |
| 38 | return false; | 38 | return false; |
| 39 | 39 | ||
| @@ -240,6 +240,8 @@ invalid_direction: | |||
| 240 | foreach(Color::Color color, movements.keys()) | 240 | foreach(Color::Color color, movements.keys()) |
| 241 | m_actors[color]->setPos(mapPositionToCoord(movements[color].first)); | 241 | m_actors[color]->setPos(mapPositionToCoord(movements[color].first)); |
| 242 | 242 | ||
| 243 | #ifndef QT_NO_DEBUG | ||
| 244 | /* collision sanity check: colors must be unique */ | ||
| 243 | foreach(Color::Color col, m_eatingorder.toSet()) | 245 | foreach(Color::Color col, m_eatingorder.toSet()) |
| 244 | { | 246 | { |
| 245 | QList<QPoint> found; | 247 | QList<QPoint> found; |
| @@ -252,8 +254,9 @@ invalid_direction: | |||
| 252 | } | 254 | } |
| 253 | } | 255 | } |
| 254 | if (found.count() > 1) | 256 | if (found.count() > 1) |
| 255 | qDebug() << "found" << found << "fields with color=" << col; | 257 | qCritical() << "[Collision] found" << found << "fields with color=" << col; |
| 256 | } | 258 | } |
| 259 | #endif | ||
| 257 | 260 | ||
| 258 | return map; | 261 | return map; |
| 259 | } | 262 | } |
| @@ -360,11 +363,11 @@ bool Server::waitForClientConnections() | |||
| 360 | qCritical() << "Error while creating socket:" << qPrintable(tcpSrv->errorString()); | 363 | qCritical() << "Error while creating socket:" << qPrintable(tcpSrv->errorString()); |
| 361 | return false; | 364 | return false; |
| 362 | } | 365 | } |
| 363 | qDebug() << "[Server] Listening on:" | 366 | std::cout << "[Server] Listening on: " |
| 364 | << qPrintable(QString("%1:%2").arg(tcpSrv->serverAddress().toString()) | 367 | << qPrintable(QString("%1:%2").arg(tcpSrv->serverAddress().toString()) |
| 365 | .arg(tcpSrv->serverPort())); | 368 | .arg(tcpSrv->serverPort())) << std::endl; |
| 366 | 369 | ||
| 367 | qDebug() << "[Server] Waiting for clients"; | 370 | std::cout << "[Server] Waiting for clients" << std::endl; |
| 368 | ProtoBuf::Init packet; | 371 | ProtoBuf::Init packet; |
| 369 | packet.set_maxplayers(m_maxplayers); | 372 | packet.set_maxplayers(m_maxplayers); |
| 370 | for (unsigned int i = 0; i < (m_maxplayers - m_numbots); ++i) | 373 | for (unsigned int i = 0; i < (m_maxplayers - m_numbots); ++i) |
| @@ -380,7 +383,7 @@ bool Server::waitForClientConnections() | |||
| 380 | m_clientConnections[color] = socket; | 383 | m_clientConnections[color] = socket; |
| 381 | packet.set_color(color); | 384 | packet.set_color(color); |
| 382 | Util::sendPacket(packet, socket); | 385 | Util::sendPacket(packet, socket); |
| 383 | qDebug() << "[Connect] New Player: color=" << color; | 386 | std::cout << "[Connect] New Player: color=" << qPrintable(Util::colorToString(color)) << std::endl; |
| 384 | } | 387 | } |
| 385 | 388 | ||
| 386 | for (unsigned int i = (m_maxplayers - m_numbots); i < m_maxplayers; ++i) | 389 | for (unsigned int i = (m_maxplayers - m_numbots); i < m_maxplayers; ++i) |
| @@ -425,9 +428,10 @@ void Server::sendUpdate(Transmission::map_t map, bool firstPacket) | |||
| 425 | 428 | ||
| 426 | if (!Util::sendPacket(data.data(), socket)) | 429 | if (!Util::sendPacket(data.data(), socket)) |
| 427 | { | 430 | { |
| 428 | qDebug() << "[sendUpdate] Error while sending data to client. Disconnecting..."; | 431 | qWarning() << "[Connect] Error while sending data to client" << i.key() << "-> Disconnecting..."; |
| 429 | socket->close(); | 432 | socket->close(); |
| 430 | qDebug() << "[sendUpdate] Actor" << i.key() << "is now a bot"; | 433 | std::cout << "[Connect] Actor color=" << qPrintable(Util::colorToString(i.key())) |
| 434 | << " is now a bot" << std::endl; | ||
| 431 | m_bots.append(i.key()); | 435 | m_bots.append(i.key()); |
| 432 | ++m_numbots; | 436 | ++m_numbots; |
| 433 | i.remove(); | 437 | i.remove(); |
| @@ -436,7 +440,7 @@ void Server::sendUpdate(Transmission::map_t map, bool firstPacket) | |||
| 436 | 440 | ||
| 437 | if (m_maxplayers == m_numbots) | 441 | if (m_maxplayers == m_numbots) |
| 438 | { | 442 | { |
| 439 | qDebug() << "[sendUpdate] No more real players left. Exiting..."; | 443 | std::cout << "[Connect] No more real players left. Exiting..." << std::endl; |
| 440 | qApp->quit(); | 444 | qApp->quit(); |
| 441 | } | 445 | } |
| 442 | } | 446 | } |
| @@ -594,7 +598,7 @@ void Server::keyPressUpdate() | |||
| 594 | 598 | ||
| 595 | void Server::initRoundMap() | 599 | void Server::initRoundMap() |
| 596 | { | 600 | { |
| 597 | qDebug() << "[initRoundMap] New round starts..."; | 601 | std::cout << "[Game] New round starts..." << std::endl; |
| 598 | m_tickTimer->stop(); | 602 | m_tickTimer->stop(); |
| 599 | 603 | ||
| 600 | /* reset scene and clean up items */ | 604 | /* reset scene and clean up items */ |
| @@ -605,7 +609,7 @@ void Server::initRoundMap() | |||
| 605 | Util::placeActors(map, m_maxplayers, Color::order); | 609 | Util::placeActors(map, m_maxplayers, Color::order); |
| 606 | Util::fillPoints(map); | 610 | Util::fillPoints(map); |
| 607 | 611 | ||
| 608 | #if 0 // actor eating actor tests | 612 | #if 0 // actor eating actor tests - TODO: remove |
| 609 | m_actorMovements.clear(); | 613 | m_actorMovements.clear(); |
| 610 | #if 0 | 614 | #if 0 |
| 611 | //works | 615 | //works |
| @@ -706,6 +710,8 @@ void Server::stopGame(bool delay) | |||
| 706 | return; | 710 | return; |
| 707 | } | 711 | } |
| 708 | 712 | ||
| 713 | std::cout << "[Game] Round finished..." << std::endl; | ||
| 714 | |||
| 709 | /* do next-round work */ | 715 | /* do next-round work */ |
| 710 | ++m_curRound; | 716 | ++m_curRound; |
| 711 | if(m_rounds == 0 || m_curRound < m_rounds) | 717 | if(m_rounds == 0 || m_curRound < m_rounds) |
| @@ -713,12 +719,11 @@ void Server::stopGame(bool delay) | |||
| 713 | else | 719 | else |
| 714 | { | 720 | { |
| 715 | /* end of game */ | 721 | /* end of game */ |
| 716 | qDebug() << "All round finished. Exiting..."; | 722 | std::cout << "[Game] All round finished. Exiting..." << std::endl; |
| 717 | qApp->quit(); | 723 | qApp->quit(); |
| 718 | } | 724 | } |
| 719 | } | 725 | } |
| 720 | 726 | ||
| 721 | |||
| 722 | void Server::setFinishRound() | 727 | void Server::setFinishRound() |
| 723 | { | 728 | { |
| 724 | m_finishRound = true; | 729 | m_finishRound = true; |
diff --git a/pacman-c++/util.cpp b/pacman-c++/util.cpp index bef7f0c..09b2be1 100644 --- a/pacman-c++/util.cpp +++ b/pacman-c++/util.cpp | |||
| @@ -211,6 +211,31 @@ namespace Util | |||
| 211 | return def; | 211 | return def; |
| 212 | } | 212 | } |
| 213 | 213 | ||
| 214 | const QString colorToString(Color::Color color) | ||
| 215 | { | ||
| 216 | switch(color) | ||
| 217 | { | ||
| 218 | case Color::none: | ||
| 219 | return "none"; | ||
| 220 | break; | ||
| 221 | case Color::red: | ||
| 222 | return "red"; | ||
| 223 | break; | ||
| 224 | case Color::blue: | ||
| 225 | return "blue"; | ||
| 226 | break; | ||
| 227 | case Color::green: | ||
| 228 | return "green"; | ||
| 229 | break; | ||
| 230 | case Color::yellow: | ||
| 231 | return "yellow"; | ||
| 232 | break; | ||
| 233 | default: | ||
| 234 | return "unknown"; | ||
| 235 | break; | ||
| 236 | } | ||
| 237 | } | ||
| 238 | |||
| 214 | QSharedPointer<QByteArray> createPacket(const ::google::protobuf::MessageLite& packet) | 239 | QSharedPointer<QByteArray> createPacket(const ::google::protobuf::MessageLite& packet) |
| 215 | { | 240 | { |
| 216 | qint64 packetlen = packet.ByteSize(); | 241 | qint64 packetlen = packet.ByteSize(); |
| @@ -236,7 +261,7 @@ namespace Util | |||
| 236 | int bytesWritten = socket->write(*data); | 261 | int bytesWritten = socket->write(*data); |
| 237 | if (bytesWritten != data->size()) | 262 | if (bytesWritten != data->size()) |
| 238 | { | 263 | { |
| 239 | qWarning() << "[sendPacket] Not all data has been sent:" | 264 | qDebug() << "[sendPacket] Not all data has been sent:" |
| 240 | << "written=" << bytesWritten << ", length=" << data->size(); | 265 | << "written=" << bytesWritten << ", length=" << data->size(); |
| 241 | return false; | 266 | return false; |
| 242 | } | 267 | } |
diff --git a/pacman-c++/util.h b/pacman-c++/util.h index 9812bc4..d20eaa5 100644 --- a/pacman-c++/util.h +++ b/pacman-c++/util.h | |||
| @@ -20,6 +20,7 @@ namespace Util | |||
| 20 | Transmission::field_t def = Transmission::none); | 20 | Transmission::field_t def = Transmission::none); |
| 21 | Actor::Movement transmissionMovementToActor(Transmission::field_t field, | 21 | Actor::Movement transmissionMovementToActor(Transmission::field_t field, |
| 22 | Actor::Movement def = Actor::None); | 22 | Actor::Movement def = Actor::None); |
| 23 | const QString colorToString(Color::Color color); | ||
| 23 | 24 | ||
| 24 | /* send packet with error check and flush */ | 25 | /* send packet with error check and flush */ |
| 25 | QSharedPointer<QByteArray> createPacket(const ::google::protobuf::MessageLite& packet); | 26 | QSharedPointer<QByteArray> createPacket(const ::google::protobuf::MessageLite& packet); |
