From 817dcc4e4493fb89c6d52b5e5ce1548b6a047d08 Mon Sep 17 00:00:00 2001 From: manuel Date: Sun, 10 Apr 2011 21:34:29 +0200 Subject: - first round of coding cleanup - small sound fix --- pacman-c++/util.cpp | 52 +++++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 23 deletions(-) (limited to 'pacman-c++/util.cpp') diff --git a/pacman-c++/util.cpp b/pacman-c++/util.cpp index 23826f7..3d04d9f 100644 --- a/pacman-c++/util.cpp +++ b/pacman-c++/util.cpp @@ -2,9 +2,10 @@ #include -namespace Util { - - Transmission::map_t createUninitialisedMap() { +namespace Util +{ + Transmission::map_t createUninitialisedMap() + { Transmission::map_t map; map = new Transmission::field_t*[Constants::map_size.width]; for (unsigned int i = 0; i < Constants::map_size.width; ++i) @@ -12,7 +13,8 @@ namespace Util { return map; } - Transmission::map_t createEmptyMap() { + Transmission::map_t createEmptyMap() + { Transmission::map_t map = createUninitialisedMap(); for (unsigned int x = 0; x < Constants::map_size.width; ++x) { @@ -24,8 +26,9 @@ namespace Util { } return map; } + // temporary - Transmission::map_t createDummyMap() + Transmission::map_t createDemoMap() { Transmission::map_t map = createEmptyMap(); @@ -86,9 +89,10 @@ namespace Util { return map; } - - Transmission::field_t actorMovementToTransmission(Actor::Movement mov, Transmission::field_t def) { - switch (mov) { + Transmission::field_t actorMovementToTransmission(Actor::Movement mov, Transmission::field_t def) + { + switch (mov) + { case Actor::None: return Transmission::direction_none; break; @@ -105,17 +109,18 @@ namespace Util { return Transmission::direction_down; break; default: - if (def == static_cast(-1)) { + if (def == static_cast(-1)) Q_ASSERT(false); - } else { + else return def; - } } return 0; // for pleasing the compiler } - Actor::Movement transmissionMovementToActor(Transmission::field_t field, Actor::Movement def) { - switch (field) { + Actor::Movement transmissionMovementToActor(Transmission::field_t field, Actor::Movement def) + { + switch (field) + { case Transmission::direction_none: return Actor::None; break; @@ -132,39 +137,40 @@ namespace Util { return Actor::Down; break; default: - if (def == Actor::Movement(-1)) { + if (def == Actor::Movement(-1)) Q_ASSERT(false); - } else { + else return def; - } } return Actor::None; // for pleasing the compiler } - void QByteArrayToStdString(const QByteArray& arr, std::string& str) { + void QByteArrayToStdString(const QByteArray& arr, std::string& str) + { // TODO: normal conversion to std::string won't work, // probably due to \0-bytes. //std::string dataStr = std::string(data.constData()); //std::string dataStr = QString(data).toStdString(); - for (int i=0; iwrite(data, length); - if (bytesWritten != length) { + if (bytesWritten != length) + { qDebug() << "written: " << bytesWritten; qDebug() << "strl: " << length; } Q_ASSERT(bytesWritten == length); socket->flush(); } - } -- cgit v1.2.3