diff options
Diffstat (limited to 'pacman-c++/server.cpp')
| -rw-r--r-- | pacman-c++/server.cpp | 20 |
1 files changed, 11 insertions, 9 deletions
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 | ||
| 24 | void Server::tick() | 24 | void 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 | } |
