summaryrefslogtreecommitdiffstats
path: root/pacman-c++
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2011-04-12 20:23:33 +0200
committermanuel <manuel@mausz.at>2011-04-12 20:23:33 +0200
commit6af8e7795da1e86745364af1538fa76d4e0fc07e (patch)
tree815ea747b9249a3a7ee10040c31da45c9af48fb1 /pacman-c++
parentea20d11fdaf383eab6269d5aae2558fd15c5c29e (diff)
downloadfoop-6af8e7795da1e86745364af1538fa76d4e0fc07e.tar.gz
foop-6af8e7795da1e86745364af1538fa76d4e0fc07e.tar.bz2
foop-6af8e7795da1e86745364af1538fa76d4e0fc07e.zip
minor improvments: better debug messages + no tabs :D
Diffstat (limited to 'pacman-c++')
-rw-r--r--pacman-c++/actor.cpp3
-rw-r--r--pacman-c++/block.cpp1
-rw-r--r--pacman-c++/bonuspoint.cpp1
-rw-r--r--pacman-c++/mainwidget.cpp7
-rw-r--r--pacman-c++/pacman.pro2
-rw-r--r--pacman-c++/pacman.proto10
-rw-r--r--pacman-c++/pacman.server.pro4
-rw-r--r--pacman-c++/sceneholder.cpp5
-rw-r--r--pacman-c++/server.cpp20
-rw-r--r--pacman-c++/util.cpp28
-rw-r--r--pacman-c++/util.h12
11 files changed, 46 insertions, 47 deletions
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)
188 188
189 if (direction == Actor::None) 189 if (direction == Actor::None)
190 { 190 {
191 //TODO
191 qDebug() << "pause"; 192 qDebug() << "pause";
192 m_wakaPlayer->pause(); 193 m_wakaPlayer->pause();
193 } 194 }
@@ -197,8 +198,6 @@ void Actor::move(Actor::Movement direction)
197 198
198void Actor::moveByServer(Actor::Movement direction) 199void Actor::moveByServer(Actor::Movement direction)
199{ 200{
200 qDebug() << "move by server";
201
202 QPointF endpos(0, 0); 201 QPointF endpos(0, 0);
203 switch(direction) 202 switch(direction)
204 { 203 {
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)
19 } 19 }
20 setPixmap(m_pixmaps.find(color).value()); 20 setPixmap(m_pixmaps.find(color).value());
21 setNeighbours(neighbours); 21 setNeighbours(neighbours);
22 //qDebug() << "loading block w color: " << color;
23} 22}
24 23
25void Block::setNeighbours(unsigned int neighbours) 24void 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)
33 33
34void BonusPoint::onDie(Actor *actor) 34void BonusPoint::onDie(Actor *actor)
35{ 35{
36 qDebug() << "here comes the cherry.. ";
37 actor->eatingCherry(); 36 actor->eatingCherry();
38} 37}
39 38
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)
31 connect(sendTimer, SIGNAL(timeout()), this, SLOT(sendKeyUpdate())); 31 connect(sendTimer, SIGNAL(timeout()), this, SLOT(sendKeyUpdate()));
32 sendTimer->start(Constants::tick); 32 sendTimer->start(Constants::tick);
33 33
34 qDebug() << "mycolor=" << m_scene->color(); 34 qDebug() << "[Connect] mycolor=" << m_scene->color();
35 35
36 //TODO: play intro as soon as there are enough players 36 //TODO: play intro as soon as there are enough players
37 //connect(AudioPlayer::self(), SIGNAL(finished()), this, SLOT(startGame())); 37 //connect(AudioPlayer::self(), SIGNAL(finished()), this, SLOT(startGame()));
@@ -134,7 +134,6 @@ void MainWidget::tick()
134 std::string dataStr; 134 std::string dataStr;
135 Util::QByteArrayToStdString(m_socket->readAll(), dataStr); 135 Util::QByteArrayToStdString(m_socket->readAll(), dataStr);
136 136
137 //qDebug() << "read str " << dataStr.length();
138 ProtoBuf::MapUpdate packet; 137 ProtoBuf::MapUpdate packet;
139 bool worked = packet.ParseFromString(dataStr); 138 bool worked = packet.ParseFromString(dataStr);
140 Q_ASSERT(worked); 139 Q_ASSERT(worked);
@@ -174,7 +173,7 @@ void MainWidget::sendKeyUpdate()
174 return; 173 return;
175 if (m_currentKey == Transmission::direction_none) 174 if (m_currentKey == Transmission::direction_none)
176 return; 175 return;
177 qDebug() << "send key: " << m_currentKey; 176 qDebug() << "[SendKey] key=" << m_currentKey;
178 ProtoBuf::KeyPressUpdate packet; 177 ProtoBuf::KeyPressUpdate packet;
179 packet.set_newkey(m_currentKey); 178 packet.set_newkey(m_currentKey);
180 Util::sendPacket(packet, m_socket); 179 Util::sendPacket(packet, m_socket);
@@ -207,7 +206,7 @@ Color::Color MainWidget::connectToServer()
207 // check command line arguments for server port 206 // check command line arguments for server port
208 const QStringList &args = QCoreApplication::arguments(); 207 const QStringList &args = QCoreApplication::arguments();
209 QString srv = args.value(1, "127.0.0.1"); 208 QString srv = args.value(1, "127.0.0.1");
210 qDebug() << "srv: " << srv; 209 qDebug() << "[Connect] server=" << srv;
211 210
212 // connect to server 211 // connect to server
213 m_socket = new QTcpSocket(this); 212 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 \
15 clicklabel.cpp \ 15 clicklabel.cpp \
16 sceneholder.cpp \ 16 sceneholder.cpp \
17 util.cpp \ 17 util.cpp \
18 gameentity.cpp 18 gameentity.cpp
19HEADERS += pixmapitem.h \ 19HEADERS += pixmapitem.h \
20 actor.h \ 20 actor.h \
21 animationmanager.h \ 21 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 @@
1package ProtoBuf; 1package ProtoBuf;
2 2
3message KeyPressUpdate { 3message KeyPressUpdate {
4 required uint32 newKey = 1; 4 required uint32 newKey = 1;
5} 5}
6 6
7//TODO move points inside array 7//TODO move points inside array
8message MapUpdate { 8message MapUpdate {
9 repeated uint32 field = 1 [packed=true]; 9 repeated uint32 field = 1 [packed=true];
10 repeated uint32 round_points = 2; 10 repeated uint32 round_points = 2;
11 repeated uint32 game_points = 3; 11 repeated uint32 game_points = 3;
12} 12}
13 13
14message WhoAmI { 14message WhoAmI {
15 required uint32 color = 1; 15 required uint32 color = 1;
16} 16}
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 \
17 sceneholder.cpp \ 17 sceneholder.cpp \
18 util.cpp \ 18 util.cpp \
19 clicklabel.cpp \ 19 clicklabel.cpp \
20 gameentity.cpp 20 gameentity.cpp
21HEADERS += pixmapitem.h \ 21HEADERS += pixmapitem.h \
22 actor.h \ 22 actor.h \
23 animationmanager.h \ 23 animationmanager.h \
@@ -30,7 +30,7 @@ HEADERS += pixmapitem.h \
30 sceneholder.h \ 30 sceneholder.h \
31 util.h \ 31 util.h \
32 clicklabel.h \ 32 clicklabel.h \
33 gameentity.h 33 gameentity.h
34RESOURCES += pacman.qrc 34RESOURCES += pacman.qrc
35 35
36OBJECTS_DIR = .obj 36OBJECTS_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)
116 Actor::Movement direction = 116 Actor::Movement direction =
117 Util::transmissionMovementToActor(cur & Transmission::direction_mask); 117 Util::transmissionMovementToActor(cur & Transmission::direction_mask);
118 actor->move(direction); 118 actor->move(direction);
119 qDebug() << "actor " << color << " move " << direction << "to " << x << y; 119 qDebug() << "[SceneUpdate] actor moves: color=" << color
120 << "direction=" << direction << "newpos=" << QPoint(x, y);
120 } 121 }
121 } 122 }
122 else if (cur & Transmission::empty) 123 else if (cur & Transmission::empty)
@@ -125,7 +126,7 @@ void SceneHolder::updateMap(const Transmission::map_t& map)
125 } 126 }
126 else 127 else
127 { 128 {
128 qWarning() << "Unknown data value at" << cur; 129 qWarning() << "Unknown data. value=" << cur;
129 Q_ASSERT(false); 130 Q_ASSERT(false);
130 } 131 }
131 132
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)
10 : SceneHolder(parent) 10 : SceneHolder(parent)
11{ 11{
12 12
13 qDebug() << "waiting for clients"; 13 qDebug() << "[Server] Waiting for clients";
14 waitForClientConnections(); 14 waitForClientConnections();
15 qDebug() << "clients connected"; 15 qDebug() << "[Server] All Clients connected";
16 16
17 updateMap(Util::createDemoMap()); 17 updateMap(Util::createDemoMap());
18 18
@@ -23,7 +23,7 @@ Server::Server(QWidget *parent)
23 23
24void Server::tick() 24void Server::tick()
25{ 25{
26 qDebug() << "doing srv update"; 26 qDebug() << "[Tick] Doing server update";
27 Transmission::map_t map = calculateUpdates(); 27 Transmission::map_t map = calculateUpdates();
28 updateMap(map); 28 updateMap(map);
29 29
@@ -49,7 +49,8 @@ invalid_direction:
49 ++turn; 49 ++turn;
50 Actor *actor = m_actors.value(i.key()); 50 Actor *actor = m_actors.value(i.key());
51 QPoint mapPosition = CoordToMapPosition(actor->pos().toPoint()); 51 QPoint mapPosition = CoordToMapPosition(actor->pos().toPoint());
52 qDebug() << "actor " << i.key() << " is at " << mapPosition << "moving " << i.value(); 52 qDebug() << "[Calc] Actor wants to move: color=" << i.key()
53 << "pos=" << mapPosition << "direction=" << i.value();
53 54
54 QPoint newMapPosition = mapPosition; 55 QPoint newMapPosition = mapPosition;
55 switch (i.value()) 56 switch (i.value())
@@ -90,11 +91,12 @@ invalid_direction:
90 GameEntity *item = visualMap[newMapPosition.x()][newMapPosition.y()]; 91 GameEntity *item = visualMap[newMapPosition.x()][newMapPosition.y()];
91 if (item != NULL && oldItem != item) 92 if (item != NULL && oldItem != item)
92 { 93 {
93 qDebug() << "item at new actor location found"; 94 qDebug() << "[Calc] Found item at new actor location";
94 if (!item->checkEnter(actor)) 95 if (!item->checkEnter(actor))
95 { 96 {
96 /* movement invalid. e.g. move against wall */ 97 /* movement invalid. e.g. move against wall */
97 newMapPosition = mapPosition; 98 newMapPosition = mapPosition;
99 qDebug() << "[Calc] Item blocks actor";
98 } 100 }
99 else 101 else
100 { 102 {
@@ -115,7 +117,7 @@ invalid_direction:
115 if (turn == 1 && i.value() != actor->direction()) 117 if (turn == 1 && i.value() != actor->direction())
116 { 118 {
117 /* set direction back to last known direction and try again */ 119 /* set direction back to last known direction and try again */
118 qDebug() << "Movement was blocked. Try last known direction"; 120 qDebug() << "[Calc] Movement was blocked. Trying last known actor direction";
119 m_actorMovements[i.key()] = actor->direction(); 121 m_actorMovements[i.key()] = actor->direction();
120 goto invalid_direction; 122 goto invalid_direction;
121 } 123 }
@@ -123,6 +125,7 @@ invalid_direction:
123 { 125 {
124 /* second turn didn't work too -> stop movement */ 126 /* second turn didn't work too -> stop movement */
125 m_actorMovements[i.key()] = Actor::None; 127 m_actorMovements[i.key()] = Actor::None;
128 qDebug() << "[Calc] No good direction known. Movement stopped";
126 } 129 }
127 } 130 }
128 131
@@ -159,7 +162,6 @@ QSharedPointer<ProtoBuf::MapUpdate> Server::createUpdatePacket(Transmission::map
159 updatePacket->add_game_points(m_actors.value(Color::order[i])->getGamePoints()); 162 updatePacket->add_game_points(m_actors.value(Color::order[i])->getGamePoints());
160 } 163 }
161 164
162 //qDebug() << "field sz "<< updatePacket->field_size();
163 return updatePacket; 165 return updatePacket;
164} 166}
165 167
@@ -191,7 +193,7 @@ void Server::waitForClientConnections()
191 packet.set_color(color); 193 packet.set_color(color);
192 Util::sendPacket(packet, socket); 194 Util::sendPacket(packet, socket);
193 195
194 qDebug() << "new player of col " << color; 196 qDebug() << "[Connect] New Player: color=" << color;
195 } 197 }
196} 198}
197 199
@@ -219,7 +221,7 @@ void Server::keyPressUpdate()
219 bool worked = packet.ParseFromString(dataStr); 221 bool worked = packet.ParseFromString(dataStr);
220 Q_ASSERT(worked); 222 Q_ASSERT(worked);
221 Transmission::field_t direction = packet.newkey(); 223 Transmission::field_t direction = packet.newkey();
222 qDebug() << "[keypress] actor=" << color << ", direction=" << direction; 224 qDebug() << "[KeyPress] actor=" << color << "direction=" << direction;
223 m_actorMovements[color] = Util::transmissionMovementToActor(direction); 225 m_actorMovements[color] = Util::transmissionMovementToActor(direction);
224 } 226 }
225 } 227 }
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
6{ 6{
7 Transmission::map_t createUninitialisedMap() 7 Transmission::map_t createUninitialisedMap()
8 { 8 {
9 Transmission::map_t map; 9 Transmission::map_t map;
10 map = new Transmission::field_t*[Constants::map_size.width]; 10 map = new Transmission::field_t*[Constants::map_size.width];
11 for (unsigned int i = 0; i < Constants::map_size.width; ++i) 11 for (unsigned int i = 0; i < Constants::map_size.width; ++i)
12 map[i] = new Transmission::field_t[Constants::map_size.height]; 12 map[i] = new Transmission::field_t[Constants::map_size.height];
13 return map; 13 return map;
14 } 14 }
15 15
16 Transmission::map_t createEmptyMap() 16 Transmission::map_t createEmptyMap()
17 { 17 {
@@ -153,20 +153,20 @@ namespace Util
153 153
154 void sendPacket(const ::google::protobuf::Message& packet, QTcpSocket *socket) 154 void sendPacket(const ::google::protobuf::Message& packet, QTcpSocket *socket)
155 { 155 {
156 std::string dataStr = packet.SerializeAsString(); 156 std::string dataStr = packet.SerializeAsString();
157 const char *data = dataStr.c_str(); 157 const char *data = dataStr.c_str();
158 sendPacket(data, dataStr.length(), socket); 158 sendPacket(data, dataStr.length(), socket);
159 } 159 }
160 160
161 void sendPacket(const char *data, unsigned int length, QTcpSocket *socket) 161 void sendPacket(const char *data, unsigned int length, QTcpSocket *socket)
162 { 162 {
163 unsigned int bytesWritten = socket->write(data, length); 163 unsigned int bytesWritten = socket->write(data, length);
164 if (bytesWritten != length) 164 if (bytesWritten != length)
165 { 165 {
166 qDebug() << "written: " << bytesWritten; 166 qDebug() << "[sendPacket] Not all data has been sent."
167 qDebug() << "strl: " << length; 167 << "written=" << bytesWritten << ", length=" << length;
168 } 168 }
169 Q_ASSERT(bytesWritten == length); 169 Q_ASSERT(bytesWritten == length);
170 socket->flush(); 170 socket->flush();
171 } 171 }
172} 172}
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;
9 9
10namespace Util 10namespace Util
11{ 11{
12 Transmission::map_t createUninitialisedMap(); 12 Transmission::map_t createUninitialisedMap();
13 Transmission::map_t createDemoMap(); 13 Transmission::map_t createDemoMap();
14 Transmission::map_t createEmptyMap(); 14 Transmission::map_t createEmptyMap();
15 15
16 // default is to assert false with -1 16 // default is to assert false with -1
17 Transmission::field_t actorMovementToTransmission(Actor::Movement mov, 17 Transmission::field_t actorMovementToTransmission(Actor::Movement mov,
@@ -19,10 +19,10 @@ namespace Util
19 Actor::Movement transmissionMovementToActor(Transmission::field_t field, 19 Actor::Movement transmissionMovementToActor(Transmission::field_t field,
20 Actor::Movement def = Actor::None); 20 Actor::Movement def = Actor::None);
21 21
22 void QByteArrayToStdString(const QByteArray& arr, std::string& str); 22 void QByteArrayToStdString(const QByteArray& arr, std::string& str);
23 23
24 // send packet with error check and flush 24 // send packet with error check and flush
25 void sendPacket(const ::google::protobuf::Message& packet, QTcpSocket *socket); 25 void sendPacket(const ::google::protobuf::Message& packet, QTcpSocket *socket);
26 void sendPacket(const char *data, unsigned int length, QTcpSocket *socket); 26 void sendPacket(const char *data, unsigned int length, QTcpSocket *socket);
27} 27}
28#endif // UTIL_H 28#endif // UTIL_H