diff options
author | Andrei Karas <akaras@inbox.ru> | 2011-06-26 22:38:40 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2011-06-26 22:38:40 +0300 |
commit | 3d6d504c4bad50f64d4d54213b13439e938aa517 (patch) | |
tree | 309ae16c4218f509b68c1032368cccb617bc8dd0 | |
parent | 52b44e43f282882a83a6c7591c454c1b38ca55d5 (diff) | |
download | manaplus-3d6d504c4bad50f64d4d54213b13439e938aa517.tar.gz manaplus-3d6d504c4bad50f64d4d54213b13439e938aa517.tar.bz2 manaplus-3d6d504c4bad50f64d4d54213b13439e938aa517.tar.xz manaplus-3d6d504c4bad50f64d4d54213b13439e938aa517.zip |
Bit improve speed in map getwalk.
-rw-r--r-- | src/being.h | 1 | ||||
-rw-r--r-- | src/gui/minimap.cpp | 12 | ||||
-rw-r--r-- | src/localplayer.cpp | 44 | ||||
-rw-r--r-- | src/map.cpp | 20 | ||||
-rw-r--r-- | src/map.h | 1 |
5 files changed, 42 insertions, 36 deletions
diff --git a/src/being.h b/src/being.h index ddcef1930..b34773ab2 100644 --- a/src/being.h +++ b/src/being.h @@ -100,6 +100,7 @@ class Being : public ActorSprite, public ConfigListener { public: friend class BeingEquipBackend; + friend class LocalPlayer; /** * Action the being is currently performing diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index 32887466c..dd0edc0ba 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -130,11 +130,13 @@ void Minimap::setMap(Map *map) setVisible(false); return; } - for (int y = 0; y < surface->h; y ++) - { - for (int x = 0; x < surface->w; x ++) - *(data ++) = -map->getWalk(x, y); - } + const int size = surface->h * surface->w; + const int mask = (Map::BLOCKMASK_WALL | Map::BLOCKMASK_AIR + | Map::BLOCKMASK_WATER); + + for (int ptr = 0; ptr < size; ptr ++) + *(data ++) = -!(map->mMetaTiles[ptr].blockmask & mask); + SDL_UnlockSurface(surface); mMapImage = Image::load(surface); diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 040020001..ecd75594b 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -1127,23 +1127,19 @@ void LocalPlayer::startWalking(unsigned char dir) #endif { // Prevent skipping corners over colliding tiles - if (dx && !mMap->getWalk(getTileX() + dx, getTileY(), getWalkMask())) + if (dx && !mMap->getWalk(mX + dx, mY, getWalkMask())) dx = 0; - if (dy && !mMap->getWalk(getTileX(), getTileY() + dy, getWalkMask())) + if (dy && !mMap->getWalk(mX, mY + dy, getWalkMask())) dy = 0; // Choose a straight direction when diagonal target is blocked - if (dx && dy && !mMap->getWalk(getTileX() + dx, getTileY() + dy, - getWalkMask())) - { + if (dx && dy && !mMap->getWalk(mX + dx, mY + dy, getWalkMask())) dx = 0; - } // Walk to where the player can actually go - if ((dx || dy) && mMap->getWalk(getTileX() + dx, getTileY() + dy, - getWalkMask())) + if ((dx || dy) && mMap->getWalk(mX + dx, mY + dy, getWalkMask())) { - setDestination(getTileX() + dx, getTileY() + dy); + setDestination(mX + dx, mY + dy); } else if (dir != mDirection) { @@ -2248,44 +2244,44 @@ void LocalPlayer::crazyMove8() int mult = 1; - if (mMap->getWalk(getTileX() + movesX[idx][0], + if (mMap->getWalk(mX + movesX[idx][0], getTileY() + movesY[idx][0], getWalkMask())) { - while (mMap->getWalk(getTileX() + movesX[idx][0] * mult, - getTileY() + movesY[idx][0] * mult, + while (mMap->getWalk(mX + movesX[idx][0] * mult, + mY + movesY[idx][0] * mult, getWalkMask()) && mult <= dist) { mult ++; } move(movesX[idx][0] * (mult - 1), movesY[idx][0] * (mult - 1)); } - else if (mMap->getWalk(getTileX() + movesX[idx][1], - getTileY() + movesY[idx][1], getWalkMask())) + else if (mMap->getWalk(mX + movesX[idx][1], + mY + movesY[idx][1], getWalkMask())) { - while (mMap->getWalk(getTileX() + movesX[idx][1] * mult, - getTileY() + movesY[idx][1] * mult, + while (mMap->getWalk(mX + movesX[idx][1] * mult, + mY + movesY[idx][1] * mult, getWalkMask()) && mult <= dist) { mult ++; } move(movesX[idx][1] * (mult - 1), movesY[idx][1] * (mult - 1)); } - else if (mMap->getWalk(getTileX() + movesX[idx][2], - getTileY() + movesY[idx][2], getWalkMask())) + else if (mMap->getWalk(mX + movesX[idx][2], + mY + movesY[idx][2], getWalkMask())) { - while (mMap->getWalk(getTileX() + movesX[idx][2] * mult, - getTileY() + movesY[idx][2] * mult, + while (mMap->getWalk(mX + movesX[idx][2] * mult, + mY + movesY[idx][2] * mult, getWalkMask()) && mult <= dist) { mult ++; } move(movesX[idx][2] * (mult - 1), movesY[idx][2] * (mult - 1)); } - else if (mMap->getWalk(getTileX() + movesX[idx][3], - getTileY() + movesY[idx][3], getWalkMask())) + else if (mMap->getWalk(mX + movesX[idx][3], + mY + movesY[idx][3], getWalkMask())) { - while (mMap->getWalk(getTileX() + movesX[idx][3] * mult, - getTileY() + movesY[idx][3] * mult, + while (mMap->getWalk(mX + movesX[idx][3] * mult, + mY + movesY[idx][3] * mult, getWalkMask()) && mult <= dist) { mult ++; diff --git a/src/map.cpp b/src/map.cpp index 773e6ecdc..66c2315ee 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -676,12 +676,14 @@ void Map::drawCollision(Graphics *graphics, int scrollX, int scrollY, int width = 0; int x0 = x; - if (!getWalk(x, y, BLOCKMASK_WALL)) +// if (!getWalk(x, y, BLOCKMASK_WALL)) + if (mMetaTiles[x + y * mWidth].blockmask & BLOCKMASK_WALL) { width = 32; for (int x2 = x + 1; x < endX; x2 ++) { - if (getWalk(x2, y, BLOCKMASK_WALL)) +// if (getWalk(x2, y, BLOCKMASK_WALL)) + if (!(mMetaTiles[x2 + y * mWidth].blockmask & BLOCKMASK_WALL)) break; width += 32; x ++; @@ -698,12 +700,14 @@ void Map::drawCollision(Graphics *graphics, int scrollX, int scrollY, } } - if (x < endX && !getWalk(x, y, BLOCKMASK_AIR)) +// if (x < endX && !getWalk(x, y, BLOCKMASK_AIR)) + if (x < endX && mMetaTiles[x + y * mWidth].blockmask & BLOCKMASK_AIR) { width = 32; for (int x2 = x + 1; x < endX; x2 ++) { - if (getWalk(x2, y, BLOCKMASK_AIR)) + if (!(mMetaTiles[x2 + y * mWidth].blockmask & BLOCKMASK_AIR)) + //if (getWalk(x2, y, BLOCKMASK_AIR)) break; width += 32; x ++; @@ -720,12 +724,14 @@ void Map::drawCollision(Graphics *graphics, int scrollX, int scrollY, } } - if (x < endX && !getWalk(x, y, BLOCKMASK_WATER)) + if (x < endX && mMetaTiles[x + y * mWidth].blockmask & BLOCKMASK_WATER) +// if (x < endX && !getWalk(x, y, BLOCKMASK_WATER)) { width = 32; for (int x2 = x + 1; x < endX; x2 ++) { - if (getWalk(x2, y, BLOCKMASK_WATER)) + if (!(mMetaTiles[x2 + y * mWidth].blockmask & BLOCKMASK_WATER)) +// if (getWalk(x2, y, BLOCKMASK_WATER)) break; width += 32; x ++; @@ -856,7 +862,7 @@ void Map::blockTile(int x, int y, BlockType type) bool Map::getWalk(int x, int y, unsigned char walkmask) const { // You can't walk outside of the map - if (!contains(x, y)) + if (x < 0 || y < 0 || x >= mWidth || y >= mHeight) return false; // Check if the tile is walkable @@ -464,6 +464,7 @@ class Map : public Properties, public ConfigListener protected: friend class Actor; + friend class Minimap; /** * Adds an actor to the map. |