diff options
author | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-03-24 22:30:09 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <thorbjorn@lindeijer.nl> | 2012-03-24 22:30:09 +0100 |
commit | bbb4c1c61863b9032af2291bff20814733995391 (patch) | |
tree | 3ea88d5d789e2046c88680bf6decc088f29719fd | |
parent | 096b2cd614c521db3dd5b26508ce983e50acc531 (diff) | |
parent | a5690fa2a4cce2698225f1f558183f6fe306d860 (diff) | |
download | mana-bbb4c1c61863b9032af2291bff20814733995391.tar.gz mana-bbb4c1c61863b9032af2291bff20814733995391.tar.bz2 mana-bbb4c1c61863b9032af2291bff20814733995391.tar.xz mana-bbb4c1c61863b9032af2291bff20814733995391.zip |
Merge branch '0.6'
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/CMakeLists.txt | 6 | ||||
-rw-r--r-- | src/cpp0x_compat/cstdint | 7 | ||||
-rw-r--r-- | src/gui/serverdialog.cpp | 4 | ||||
-rw-r--r-- | src/gui/serverdialog.h | 2 | ||||
-rw-r--r-- | src/gui/viewport.cpp | 62 | ||||
-rw-r--r-- | src/utils/mutex.h | 5 |
7 files changed, 59 insertions, 28 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 3710a027..2e06d02d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,7 @@ FIND_PACKAGE(Gettext) OPTION(WITH_OPENGL "Enable OpenGL support" ON) OPTION(ENABLE_NLS "Enable building of tranlations" ON) OPTION(ENABLE_MANASERV "Enable Manaserv support" OFF) +OPTION(ENABLE_CPP0X "Enable use of C++0x features" ON) IF (WIN32) SET(PKG_DATADIR ".") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 977524e9..e0a42478 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -34,7 +34,11 @@ ENDIF() SET(FLAGS "-DPACKAGE_VERSION=\\\"${VERSION}\\\"") SET(FLAGS "${FLAGS} -DPKG_DATADIR=\\\"${PKG_DATADIR}/\\\"") SET(FLAGS "${FLAGS} -DLOCALEDIR=\\\"${LOCALEDIR}/\\\"") -SET(FLAGS "${FLAGS} -std=c++0x") +IF (ENABLE_CPP0X) + SET(FLAGS "${FLAGS} -std=c++0x -DENABLE_CPP0X=1") +ELSE() + INCLUDE_DIRECTORIES("cpp0x_compat") +ENDIF() IF (ENABLE_NLS) SET(FLAGS "${FLAGS} -DENABLE_NLS=1") diff --git a/src/cpp0x_compat/cstdint b/src/cpp0x_compat/cstdint new file mode 100644 index 00000000..d8d71d9d --- /dev/null +++ b/src/cpp0x_compat/cstdint @@ -0,0 +1,7 @@ +/* + * Compatibility header used when the compiler doesn't support C++0x. + * + * It doesn't seem necessary for it to contain anything, at least GCC 4.2.1 + * compiles Mana fine so it apparently understands types like uint16_t by + * default. + */ diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index 0a2b96f4..9802224b 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -78,13 +78,13 @@ ServersListModel::ServersListModel(ServerInfos *servers, ServerDialog *parent): int ServersListModel::getNumberOfElements() { - MutexLocker lock = mParent->lock(); + MutexLocker lock(mParent->getMutex()); return mServers->size(); } std::string ServersListModel::getElementAt(int elementIndex) { - MutexLocker lock = mParent->lock(); + MutexLocker lock(mParent->getMutex()); const ServerInfo &server = mServers->at(elementIndex); std::string myServer; myServer += server.hostname; diff --git a/src/gui/serverdialog.h b/src/gui/serverdialog.h index eedf5134..cf9e62e7 100644 --- a/src/gui/serverdialog.h +++ b/src/gui/serverdialog.h @@ -113,7 +113,7 @@ class ServerDialog : public Window, protected: friend class ServersListModel; - MutexLocker lock() { return MutexLocker(&mMutex); } + Mutex *getMutex() { return &mMutex; } friend class CustomServerDialog; /** diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index fd6bc6a3..1b5b00c3 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -97,8 +97,12 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) { static int lastTick = tick_time; + // Check whether map was successfully loaded since + // the rest of this function relies on it if (!mMap || !local_player) { + // Render unicolor background to avoid + // rendering issues gcnGraphics->setColor(gcn::Color(64, 64, 64)); gcnGraphics->fillRectangle( gcn::Rectangle(0, 0, getWidth(), getHeight())); @@ -178,37 +182,47 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) }; // Don't move camera so that the end of the map is on screen - const int viewXmax = - mMap->getWidth() * mMap->getTileWidth() - graphics->getWidth(); - const int viewYmax = - mMap->getHeight() * mMap->getTileHeight() - graphics->getHeight(); - if (mMap) + const int mapWidthPixels = mMap->getWidth() * mMap->getTileWidth(); + const int mapHeightPixels = mMap->getHeight() * mMap->getTileHeight(); + const int viewXmax = mapWidthPixels - graphics->getWidth(); + const int viewYmax = mapHeightPixels - graphics->getHeight(); + if (mPixelViewX < 0) + mPixelViewX = 0; + if (mPixelViewY < 0) + mPixelViewY = 0; + if (mPixelViewX > viewXmax) + mPixelViewX = viewXmax; + if (mPixelViewY > viewYmax) + mPixelViewY = viewYmax; + + // Center camera on map if the map is smaller than the screen + if (mapWidthPixels < graphics->getWidth()) + mPixelViewX = (mapWidthPixels - graphics->getWidth()) / 2; + if (mapHeightPixels < graphics->getHeight()) + mPixelViewY = (mapHeightPixels - graphics->getHeight()) / 2; + + // Draw black background if map is smaller than the screen + if ( mapWidthPixels < graphics->getWidth() + || mapHeightPixels < graphics->getHeight()) { - if (mPixelViewX < 0) - mPixelViewX = 0; - if (mPixelViewY < 0) - mPixelViewY = 0; - if (mPixelViewX > viewXmax) - mPixelViewX = viewXmax; - if (mPixelViewY > viewYmax) - mPixelViewY = viewYmax; + gcnGraphics->setColor(gcn::Color(0, 0, 0)); + gcnGraphics->fillRectangle( + gcn::Rectangle(0, 0, getWidth(), getHeight())); + } // Draw tiles and sprites - if (mMap) - { - mMap->draw(graphics, (int) mPixelViewX, (int) mPixelViewY); + mMap->draw(graphics, (int) mPixelViewX, (int) mPixelViewY); - if (mDebugFlags) + if (mDebugFlags) + { + if (mDebugFlags & (Map::DEBUG_GRID | Map::DEBUG_COLLISION_TILES)) { - if (mDebugFlags & (Map::DEBUG_GRID | Map::DEBUG_COLLISION_TILES)) - { - mMap->drawCollision(graphics, (int) mPixelViewX, - (int) mPixelViewY, mDebugFlags); - } - - _drawDebugPath(graphics); + mMap->drawCollision(graphics, (int) mPixelViewX, + (int) mPixelViewY, mDebugFlags); } + + _drawDebugPath(graphics); } if (local_player->getCheckNameSetting()) diff --git a/src/utils/mutex.h b/src/utils/mutex.h index 26ad754e..f7f26233 100644 --- a/src/utils/mutex.h +++ b/src/utils/mutex.h @@ -53,7 +53,9 @@ class MutexLocker { public: MutexLocker(Mutex *mutex); +#ifdef ENABLE_CPP0X MutexLocker(MutexLocker&&); +#endif ~MutexLocker(); private: @@ -93,11 +95,14 @@ inline MutexLocker::MutexLocker(Mutex *mutex): mMutex->lock(); } +#ifdef ENABLE_CPP0X inline MutexLocker::MutexLocker(MutexLocker&& rhs): mMutex(rhs.mMutex) { rhs.mMutex = NULL; } +#endif + inline MutexLocker::~MutexLocker() { if (mMutex) |