From 8b13a88127a70da7a4e307df828d65811ae5d0f1 Mon Sep 17 00:00:00 2001 From: manuel Date: Mon, 2 May 2011 17:12:11 +0200 Subject: smaller output --- pacman-c++/actor.cpp | 3 +-- pacman-c++/audio.cpp | 2 +- pacman-c++/pacman.pro | 4 ++++ pacman-c++/pacman.server.pro | 4 ++++ pacman-c++/server.cpp | 37 +++++++++++++++++++++---------------- pacman-c++/util.cpp | 27 ++++++++++++++++++++++++++- 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) for (int i = 0; i < 11; i++) { PixmapItem *img = new PixmapItem(m_pix, this); - img->setZValue(zValue() * 10); m_images.append(img); int x = i * Constants::sprite_offset + Constants::sprite_margin; int y = 5 * Constants::sprite_offset + Constants::sprite_margin; img->setSprite(x, y, Constants::field_size.width, Constants::field_size.height); - img->setZValue(zValue()); + img->setZValue(zValue() * 10); img->setVisible(false); 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 void AudioPlayer::testFinished() { if (!m_working) - qDebug() << "There's no sound for you :("; + qWarning() << "There's no sound for you :("; disconnect(this, SIGNAL(stateChanged(Phonon::State, Phonon::State)), this, SLOT(stateChanged_ex(Phonon::State, Phonon::State))); } 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 += \ PROTOS = pacman.proto include(protobuf.pri) LIBS += -lprotobuf + +CONFIG(release, debug|release) { + DEFINES += QT_NO_DEBUG_OUTPUT +} 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 += \ PROTOS = pacman.proto include(protobuf.pri) LIBS += -lprotobuf + +CONFIG(release, debug|release) { + DEFINES += QT_NO_DEBUG_OUTPUT +} 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() m_tickTimer->setInterval(Constants::tick); connect(m_tickTimer, SIGNAL(timeout()), this, SLOT(tick())); - qDebug() << "[Server] Running server..."; - qDebug() << "[Server] Max players:" << m_maxplayers; - qDebug() << "[Server] Number of bots:" << m_numbots; - qDebug() << "[Server] Number of rounds:" << m_rounds; + std::cout << "[Server] Running server..." << std::endl + << "[Server] Max players: " << m_maxplayers << std::endl + << "[Server] Number of bots: " << m_numbots << std::endl + << "[Server] Number of rounds: " << m_rounds << std::endl; if (!waitForClientConnections()) return false; @@ -240,6 +240,8 @@ invalid_direction: foreach(Color::Color color, movements.keys()) m_actors[color]->setPos(mapPositionToCoord(movements[color].first)); +#ifndef QT_NO_DEBUG + /* collision sanity check: colors must be unique */ foreach(Color::Color col, m_eatingorder.toSet()) { QList found; @@ -252,8 +254,9 @@ invalid_direction: } } if (found.count() > 1) - qDebug() << "found" << found << "fields with color=" << col; + qCritical() << "[Collision] found" << found << "fields with color=" << col; } +#endif return map; } @@ -360,11 +363,11 @@ bool Server::waitForClientConnections() qCritical() << "Error while creating socket:" << qPrintable(tcpSrv->errorString()); return false; } - qDebug() << "[Server] Listening on:" + std::cout << "[Server] Listening on: " << qPrintable(QString("%1:%2").arg(tcpSrv->serverAddress().toString()) - .arg(tcpSrv->serverPort())); + .arg(tcpSrv->serverPort())) << std::endl; - qDebug() << "[Server] Waiting for clients"; + std::cout << "[Server] Waiting for clients" << std::endl; ProtoBuf::Init packet; packet.set_maxplayers(m_maxplayers); for (unsigned int i = 0; i < (m_maxplayers - m_numbots); ++i) @@ -380,7 +383,7 @@ bool Server::waitForClientConnections() m_clientConnections[color] = socket; packet.set_color(color); Util::sendPacket(packet, socket); - qDebug() << "[Connect] New Player: color=" << color; + std::cout << "[Connect] New Player: color=" << qPrintable(Util::colorToString(color)) << std::endl; } 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) if (!Util::sendPacket(data.data(), socket)) { - qDebug() << "[sendUpdate] Error while sending data to client. Disconnecting..."; + qWarning() << "[Connect] Error while sending data to client" << i.key() << "-> Disconnecting..."; socket->close(); - qDebug() << "[sendUpdate] Actor" << i.key() << "is now a bot"; + std::cout << "[Connect] Actor color=" << qPrintable(Util::colorToString(i.key())) + << " is now a bot" << std::endl; m_bots.append(i.key()); ++m_numbots; i.remove(); @@ -436,7 +440,7 @@ void Server::sendUpdate(Transmission::map_t map, bool firstPacket) if (m_maxplayers == m_numbots) { - qDebug() << "[sendUpdate] No more real players left. Exiting..."; + std::cout << "[Connect] No more real players left. Exiting..." << std::endl; qApp->quit(); } } @@ -594,7 +598,7 @@ void Server::keyPressUpdate() void Server::initRoundMap() { - qDebug() << "[initRoundMap] New round starts..."; + std::cout << "[Game] New round starts..." << std::endl; m_tickTimer->stop(); /* reset scene and clean up items */ @@ -605,7 +609,7 @@ void Server::initRoundMap() Util::placeActors(map, m_maxplayers, Color::order); Util::fillPoints(map); -#if 0 // actor eating actor tests +#if 0 // actor eating actor tests - TODO: remove m_actorMovements.clear(); #if 0 //works @@ -706,6 +710,8 @@ void Server::stopGame(bool delay) return; } + std::cout << "[Game] Round finished..." << std::endl; + /* do next-round work */ ++m_curRound; if(m_rounds == 0 || m_curRound < m_rounds) @@ -713,12 +719,11 @@ void Server::stopGame(bool delay) else { /* end of game */ - qDebug() << "All round finished. Exiting..."; + std::cout << "[Game] All round finished. Exiting..." << std::endl; qApp->quit(); } } - void Server::setFinishRound() { 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 return def; } + const QString colorToString(Color::Color color) + { + switch(color) + { + case Color::none: + return "none"; + break; + case Color::red: + return "red"; + break; + case Color::blue: + return "blue"; + break; + case Color::green: + return "green"; + break; + case Color::yellow: + return "yellow"; + break; + default: + return "unknown"; + break; + } + } + QSharedPointer createPacket(const ::google::protobuf::MessageLite& packet) { qint64 packetlen = packet.ByteSize(); @@ -236,7 +261,7 @@ namespace Util int bytesWritten = socket->write(*data); if (bytesWritten != data->size()) { - qWarning() << "[sendPacket] Not all data has been sent:" + qDebug() << "[sendPacket] Not all data has been sent:" << "written=" << bytesWritten << ", length=" << data->size(); return false; } 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 Transmission::field_t def = Transmission::none); Actor::Movement transmissionMovementToActor(Transmission::field_t field, Actor::Movement def = Actor::None); + const QString colorToString(Color::Color color); /* send packet with error check and flush */ QSharedPointer createPacket(const ::google::protobuf::MessageLite& packet); -- cgit v1.2.3