From 6af8e7795da1e86745364af1538fa76d4e0fc07e Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 12 Apr 2011 20:23:33 +0200 Subject: minor improvments: better debug messages + no tabs :D --- pacman-c++/actor.cpp | 3 +-- pacman-c++/block.cpp | 1 - pacman-c++/bonuspoint.cpp | 1 - pacman-c++/mainwidget.cpp | 7 +++---- pacman-c++/pacman.pro | 2 +- pacman-c++/pacman.proto | 10 +++++----- pacman-c++/pacman.server.pro | 4 ++-- pacman-c++/sceneholder.cpp | 5 +++-- pacman-c++/server.cpp | 20 +++++++++++--------- pacman-c++/util.cpp | 28 ++++++++++++++-------------- pacman-c++/util.h | 12 ++++++------ 11 files changed, 46 insertions(+), 47 deletions(-) (limited to 'pacman-c++') diff --git a/pacman-c++/actor.cpp b/pacman-c++/actor.cpp index d53566e..a746546 100644 --- a/pacman-c++/actor.cpp +++ b/pacman-c++/actor.cpp @@ -188,6 +188,7 @@ void Actor::move(Actor::Movement direction) if (direction == Actor::None) { + //TODO qDebug() << "pause"; m_wakaPlayer->pause(); } @@ -197,8 +198,6 @@ void Actor::move(Actor::Movement direction) void Actor::moveByServer(Actor::Movement direction) { - qDebug() << "move by server"; - QPointF endpos(0, 0); switch(direction) { diff --git a/pacman-c++/block.cpp b/pacman-c++/block.cpp index c8607ac..083b203 100644 --- a/pacman-c++/block.cpp +++ b/pacman-c++/block.cpp @@ -19,7 +19,6 @@ Block::Block(Color::Color color, unsigned int neighbours, QGraphicsItem *parent) } setPixmap(m_pixmaps.find(color).value()); setNeighbours(neighbours); - //qDebug() << "loading block w color: " << color; } void Block::setNeighbours(unsigned int neighbours) diff --git a/pacman-c++/bonuspoint.cpp b/pacman-c++/bonuspoint.cpp index 5bb470e..221e32e 100644 --- a/pacman-c++/bonuspoint.cpp +++ b/pacman-c++/bonuspoint.cpp @@ -33,7 +33,6 @@ bool BonusPoint::enter(Actor* actor) void BonusPoint::onDie(Actor *actor) { - qDebug() << "here comes the cherry.. "; actor->eatingCherry(); } diff --git a/pacman-c++/mainwidget.cpp b/pacman-c++/mainwidget.cpp index ba09f7d..89cbd58 100644 --- a/pacman-c++/mainwidget.cpp +++ b/pacman-c++/mainwidget.cpp @@ -31,7 +31,7 @@ MainWidget::MainWidget(QWidget *parent) connect(sendTimer, SIGNAL(timeout()), this, SLOT(sendKeyUpdate())); sendTimer->start(Constants::tick); - qDebug() << "mycolor=" << m_scene->color(); + qDebug() << "[Connect] mycolor=" << m_scene->color(); //TODO: play intro as soon as there are enough players //connect(AudioPlayer::self(), SIGNAL(finished()), this, SLOT(startGame())); @@ -134,7 +134,6 @@ void MainWidget::tick() std::string dataStr; Util::QByteArrayToStdString(m_socket->readAll(), dataStr); - //qDebug() << "read str " << dataStr.length(); ProtoBuf::MapUpdate packet; bool worked = packet.ParseFromString(dataStr); Q_ASSERT(worked); @@ -174,7 +173,7 @@ void MainWidget::sendKeyUpdate() return; if (m_currentKey == Transmission::direction_none) return; - qDebug() << "send key: " << m_currentKey; + qDebug() << "[SendKey] key=" << m_currentKey; ProtoBuf::KeyPressUpdate packet; packet.set_newkey(m_currentKey); Util::sendPacket(packet, m_socket); @@ -207,7 +206,7 @@ Color::Color MainWidget::connectToServer() // check command line arguments for server port const QStringList &args = QCoreApplication::arguments(); QString srv = args.value(1, "127.0.0.1"); - qDebug() << "srv: " << srv; + qDebug() << "[Connect] server=" << srv; // connect to server m_socket = new QTcpSocket(this); diff --git a/pacman-c++/pacman.pro b/pacman-c++/pacman.pro index 07efc71..f8beb4a 100644 --- a/pacman-c++/pacman.pro +++ b/pacman-c++/pacman.pro @@ -15,7 +15,7 @@ SOURCES += pixmapitem.cpp \ clicklabel.cpp \ sceneholder.cpp \ util.cpp \ - gameentity.cpp + gameentity.cpp HEADERS += pixmapitem.h \ actor.h \ animationmanager.h \ diff --git a/pacman-c++/pacman.proto b/pacman-c++/pacman.proto index 0472697..40c7af0 100644 --- a/pacman-c++/pacman.proto +++ b/pacman-c++/pacman.proto @@ -1,16 +1,16 @@ package ProtoBuf; message KeyPressUpdate { - required uint32 newKey = 1; + required uint32 newKey = 1; } //TODO move points inside array message MapUpdate { - repeated uint32 field = 1 [packed=true]; - repeated uint32 round_points = 2; - repeated uint32 game_points = 3; + repeated uint32 field = 1 [packed=true]; + repeated uint32 round_points = 2; + repeated uint32 game_points = 3; } message WhoAmI { - required uint32 color = 1; + required uint32 color = 1; } diff --git a/pacman-c++/pacman.server.pro b/pacman-c++/pacman.server.pro index 1463818..075f44d 100644 --- a/pacman-c++/pacman.server.pro +++ b/pacman-c++/pacman.server.pro @@ -17,7 +17,7 @@ SOURCES += pixmapitem.cpp \ sceneholder.cpp \ util.cpp \ clicklabel.cpp \ - gameentity.cpp + gameentity.cpp HEADERS += pixmapitem.h \ actor.h \ animationmanager.h \ @@ -30,7 +30,7 @@ HEADERS += pixmapitem.h \ sceneholder.h \ util.h \ clicklabel.h \ - gameentity.h + gameentity.h RESOURCES += pacman.qrc OBJECTS_DIR = .obj diff --git a/pacman-c++/sceneholder.cpp b/pacman-c++/sceneholder.cpp index f0a5de3..f44f767 100644 --- a/pacman-c++/sceneholder.cpp +++ b/pacman-c++/sceneholder.cpp @@ -116,7 +116,8 @@ void SceneHolder::updateMap(const Transmission::map_t& map) Actor::Movement direction = Util::transmissionMovementToActor(cur & Transmission::direction_mask); actor->move(direction); - qDebug() << "actor " << color << " move " << direction << "to " << x << y; + qDebug() << "[SceneUpdate] actor moves: color=" << color + << "direction=" << direction << "newpos=" << QPoint(x, y); } } else if (cur & Transmission::empty) @@ -125,7 +126,7 @@ void SceneHolder::updateMap(const Transmission::map_t& map) } else { - qWarning() << "Unknown data value at" << cur; + qWarning() << "Unknown data. value=" << cur; Q_ASSERT(false); } diff --git a/pacman-c++/server.cpp b/pacman-c++/server.cpp index b7cd1a0..1c42174 100644 --- a/pacman-c++/server.cpp +++ b/pacman-c++/server.cpp @@ -10,9 +10,9 @@ Server::Server(QWidget *parent) : SceneHolder(parent) { - qDebug() << "waiting for clients"; + qDebug() << "[Server] Waiting for clients"; waitForClientConnections(); - qDebug() << "clients connected"; + qDebug() << "[Server] All Clients connected"; updateMap(Util::createDemoMap()); @@ -23,7 +23,7 @@ Server::Server(QWidget *parent) void Server::tick() { - qDebug() << "doing srv update"; + qDebug() << "[Tick] Doing server update"; Transmission::map_t map = calculateUpdates(); updateMap(map); @@ -49,7 +49,8 @@ invalid_direction: ++turn; Actor *actor = m_actors.value(i.key()); QPoint mapPosition = CoordToMapPosition(actor->pos().toPoint()); - qDebug() << "actor " << i.key() << " is at " << mapPosition << "moving " << i.value(); + qDebug() << "[Calc] Actor wants to move: color=" << i.key() + << "pos=" << mapPosition << "direction=" << i.value(); QPoint newMapPosition = mapPosition; switch (i.value()) @@ -90,11 +91,12 @@ invalid_direction: GameEntity *item = visualMap[newMapPosition.x()][newMapPosition.y()]; if (item != NULL && oldItem != item) { - qDebug() << "item at new actor location found"; + qDebug() << "[Calc] Found item at new actor location"; if (!item->checkEnter(actor)) { /* movement invalid. e.g. move against wall */ newMapPosition = mapPosition; + qDebug() << "[Calc] Item blocks actor"; } else { @@ -115,7 +117,7 @@ invalid_direction: if (turn == 1 && i.value() != actor->direction()) { /* set direction back to last known direction and try again */ - qDebug() << "Movement was blocked. Try last known direction"; + qDebug() << "[Calc] Movement was blocked. Trying last known actor direction"; m_actorMovements[i.key()] = actor->direction(); goto invalid_direction; } @@ -123,6 +125,7 @@ invalid_direction: { /* second turn didn't work too -> stop movement */ m_actorMovements[i.key()] = Actor::None; + qDebug() << "[Calc] No good direction known. Movement stopped"; } } @@ -159,7 +162,6 @@ QSharedPointer Server::createUpdatePacket(Transmission::map updatePacket->add_game_points(m_actors.value(Color::order[i])->getGamePoints()); } - //qDebug() << "field sz "<< updatePacket->field_size(); return updatePacket; } @@ -191,7 +193,7 @@ void Server::waitForClientConnections() packet.set_color(color); Util::sendPacket(packet, socket); - qDebug() << "new player of col " << color; + qDebug() << "[Connect] New Player: color=" << color; } } @@ -219,7 +221,7 @@ void Server::keyPressUpdate() bool worked = packet.ParseFromString(dataStr); Q_ASSERT(worked); Transmission::field_t direction = packet.newkey(); - qDebug() << "[keypress] actor=" << color << ", direction=" << direction; + qDebug() << "[KeyPress] actor=" << color << "direction=" << direction; m_actorMovements[color] = Util::transmissionMovementToActor(direction); } } diff --git a/pacman-c++/util.cpp b/pacman-c++/util.cpp index e82c961..999c765 100644 --- a/pacman-c++/util.cpp +++ b/pacman-c++/util.cpp @@ -6,12 +6,12 @@ namespace Util { Transmission::map_t createUninitialisedMap() { - Transmission::map_t map; + Transmission::map_t map; map = new Transmission::field_t*[Constants::map_size.width]; for (unsigned int i = 0; i < Constants::map_size.width; ++i) map[i] = new Transmission::field_t[Constants::map_size.height]; - return map; - } + return map; + } Transmission::map_t createEmptyMap() { @@ -153,20 +153,20 @@ namespace Util void sendPacket(const ::google::protobuf::Message& packet, QTcpSocket *socket) { - std::string dataStr = packet.SerializeAsString(); - const char *data = dataStr.c_str(); - sendPacket(data, dataStr.length(), socket); - } + std::string dataStr = packet.SerializeAsString(); + const char *data = dataStr.c_str(); + sendPacket(data, dataStr.length(), socket); + } void sendPacket(const char *data, unsigned int length, QTcpSocket *socket) { - unsigned int bytesWritten = socket->write(data, length); + unsigned int bytesWritten = socket->write(data, length); if (bytesWritten != length) { - qDebug() << "written: " << bytesWritten; - qDebug() << "strl: " << length; - } - Q_ASSERT(bytesWritten == length); - socket->flush(); - } + qDebug() << "[sendPacket] Not all data has been sent." + << "written=" << bytesWritten << ", length=" << length; + } + Q_ASSERT(bytesWritten == length); + socket->flush(); + } } diff --git a/pacman-c++/util.h b/pacman-c++/util.h index f68af67..9f7f784 100644 --- a/pacman-c++/util.h +++ b/pacman-c++/util.h @@ -9,9 +9,9 @@ class QTcpSocket; namespace Util { - Transmission::map_t createUninitialisedMap(); + Transmission::map_t createUninitialisedMap(); Transmission::map_t createDemoMap(); - Transmission::map_t createEmptyMap(); + Transmission::map_t createEmptyMap(); // default is to assert false with -1 Transmission::field_t actorMovementToTransmission(Actor::Movement mov, @@ -19,10 +19,10 @@ namespace Util Actor::Movement transmissionMovementToActor(Transmission::field_t field, Actor::Movement def = Actor::None); - void QByteArrayToStdString(const QByteArray& arr, std::string& str); + void QByteArrayToStdString(const QByteArray& arr, std::string& str); - // send packet with error check and flush - void sendPacket(const ::google::protobuf::Message& packet, QTcpSocket *socket); - void sendPacket(const char *data, unsigned int length, QTcpSocket *socket); + // send packet with error check and flush + void sendPacket(const ::google::protobuf::Message& packet, QTcpSocket *socket); + void sendPacket(const char *data, unsigned int length, QTcpSocket *socket); } #endif // UTIL_H -- cgit v1.2.3