diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-08-23 01:48:25 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-08-23 01:48:25 +0300 |
commit | 9505e3789cc9db6a10a68b9794a586604271b76f (patch) | |
tree | 4234b02319f04511ff1a94e0841f3ca5fa5b6a22 /src | |
parent | 2d17967845119a77aec6388bb27c47339052704a (diff) | |
download | plus-9505e3789cc9db6a10a68b9794a586604271b76f.tar.gz plus-9505e3789cc9db6a10a68b9794a586604271b76f.tar.bz2 plus-9505e3789cc9db6a10a68b9794a586604271b76f.tar.xz plus-9505e3789cc9db6a10a68b9794a586604271b76f.zip |
Add protection against infinite loop in viewport and add debug message
if some thing wrong happend.
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/viewport.cpp | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 70d02b016..a5b541a8e 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -145,8 +145,10 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) if (mScrollLaziness < 1) mScrollLaziness = 1; // Avoids division by zero + int cnt = 0; + // Apply lazy scrolling - while (lastTick < tick_time) + while (lastTick < tick_time && cnt < 32) { if (player_x > static_cast<int>(mPixelViewX) + mScrollRadius) { @@ -172,19 +174,26 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) - static_cast<int>(mPixelViewY) + mScrollRadius) / static_cast<float>(mScrollLaziness); } - lastTick++; + lastTick ++; + cnt ++; } // Auto center when player is off screen - if (player_x - static_cast<int>(mPixelViewX) > graphics->mWidth / 2 - || static_cast<int>(mPixelViewX) - player_x > graphics->mWidth / 2 - || static_cast<int>(mPixelViewY) - player_y - > graphics->getHeight() / 2 - || player_y - static_cast<int>(mPixelViewY) - > graphics->getHeight() / 2) + if (cnt > 30 || player_x - static_cast<int>(mPixelViewX) + > graphics->mWidth / 2 || static_cast<int>(mPixelViewX) + - player_x > graphics->mWidth / 2 || static_cast<int>(mPixelViewY) + - player_y > graphics->getHeight() / 2 || player_y + - static_cast<int>(mPixelViewY) > graphics->getHeight() / 2) { mPixelViewX = static_cast<float>(player_x); mPixelViewY = static_cast<float>(player_y); + if (player_x <= 0 || player_y <= 0) + { + if (debugChatTab) + debugChatTab->chatLog("incorrect player position!"); + logger->log("incorrect player position: %d, %d", + player_x, player_y); + } }; // Don't move camera so that the end of the map is on screen |