diff options
author | lukaslw | 2014-07-16 22:12:29 +0200 |
---|---|---|
committer | lukaslw | 2014-07-16 22:12:56 +0200 |
commit | 6fe1bb3c9cf8bc840b1a797debbccdf9a0d0bea8 (patch) | |
tree | 3863f4d36d57381f24cb019a449fdbac710c1a95 /engines | |
parent | b0c454fc9ba282f5f72a0c69a6b897e38eaddb82 (diff) | |
download | scummvm-rg350-6fe1bb3c9cf8bc840b1a797debbccdf9a0d0bea8.tar.gz scummvm-rg350-6fe1bb3c9cf8bc840b1a797debbccdf9a0d0bea8.tar.bz2 scummvm-rg350-6fe1bb3c9cf8bc840b1a797debbccdf9a0d0bea8.zip |
PRINCE: Pathfinding - scanDirections()
Diffstat (limited to 'engines')
-rw-r--r-- | engines/prince/graphics.cpp | 2 | ||||
-rw-r--r-- | engines/prince/prince.cpp | 134 | ||||
-rw-r--r-- | engines/prince/prince.h | 2 |
3 files changed, 135 insertions, 3 deletions
diff --git a/engines/prince/graphics.cpp b/engines/prince/graphics.cpp index 7a3e310320..d89b9bc048 100644 --- a/engines/prince/graphics.cpp +++ b/engines/prince/graphics.cpp @@ -228,7 +228,7 @@ void GraphicsMan::drawAsShadowDrawNode(Graphics::Surface *screen, DrawNode *draw void GraphicsMan::drawPixel(Graphics::Surface *screen, int32 posX, int32 posY) { byte *dst = (byte *)screen->getBasePtr(posX, posY); - *dst = 0; + *dst = 255; change(); } diff --git a/engines/prince/prince.cpp b/engines/prince/prince.cpp index 48ffc576a8..3e449c61d9 100644 --- a/engines/prince/prince.cpp +++ b/engines/prince/prince.cpp @@ -3935,9 +3935,139 @@ void PrinceEngine::approxPath() { } } -// TODO -void PrinceEngine::scanDirections() { +void PrinceEngine::freeDirectionTable() { + if (_directionTable = nullptr) { + free(_directionTable); + _directionTable = nullptr; + } +} + +int PrinceEngine::scanDirectionsFindNext(byte *tempCoordsBuf, int xDiff, int yDiff) { + + int tempX, tempY, direction; + tempX = Hero::LEFT; + if (xDiff < 0) { + tempX = Hero::RIGHT; + } + tempY = Hero::UP; + if (yDiff < 0) { + tempY = Hero::DOWN; + } + // push esi, edx + // again_point: + byte *againPointCoords = tempCoordsBuf; + while (1) { + int againPointX1 = READ_UINT16(againPointCoords); + int againPointY1 = READ_UINT16(againPointCoords + 2); + againPointCoords += 4; + if (againPointCoords == _coords) { + direction = tempX; + break; + } + int dX = againPointX1 - READ_UINT16(againPointCoords); // dx + int dY = againPointY1 - READ_UINT16(againPointCoords + 2); //bp + + if (dX != xDiff) { + direction = tempY; + break; + } + + if (dY != yDiff) { + direction = tempX; + break; + } + } + return direction; +} + +void PrinceEngine::scanDirections() { + freeDirectionTable(); + byte *tempCoordsBuf = _coordsBuf; // esi + if (tempCoordsBuf != _coords) { + int size = (_coords - tempCoordsBuf) / 2 + 1; // number of coord points plus one for end marker + _directionTable = (byte *)malloc(size); + byte *tempDirTab = _directionTable; // edi + // ebp = 0; + int direction = -1; + int lastDirection = -1; + int tempX = -1; + int tempY = -1; + + //loop + while (1) { + int x1 = READ_UINT16(tempCoordsBuf); + int y1 = READ_UINT16(tempCoordsBuf + 2); + tempCoordsBuf += 4; + if (tempCoordsBuf == _coords) { + break; + } + int x2 = READ_UINT16(tempCoordsBuf); + int y2 = READ_UINT16(tempCoordsBuf + 2); + + int xDiff = x1 - x2; // eax + int yDiff = y1 - y2; // ebx + + if (xDiff) { + if (yDiff) { + // skew + if (lastDirection != -1) { + direction = lastDirection; + if (direction == Hero::LEFT) { + if (xDiff < 0) { + //findnext + scanDirectionsFindNext(tempCoordsBuf, xDiff, yDiff); + } + } else if (direction == Hero::RIGHT) { + if (xDiff >= 0) { + //findnext + scanDirectionsFindNext(tempCoordsBuf, xDiff, yDiff); + } + } else if (direction == Hero::UP) { + if (yDiff < 0) { + //findnext + scanDirectionsFindNext(tempCoordsBuf, xDiff, yDiff); + } + } else { + if (yDiff >= 0) { + //findnext + scanDirectionsFindNext(tempCoordsBuf, xDiff, yDiff); + } + } + } else { + //no direction at all + // find next + scanDirectionsFindNext(tempCoordsBuf, xDiff, yDiff); + } + } else { + direction = Hero::LEFT; + if (xDiff < 0) { + direction = Hero::RIGHT; + } + } + } else { + //updown_dominates + if (yDiff) { + direction = Hero::UP; + if (yDiff < 0) { + direction = Hero::DOWN; + } + } else { + //skip_point + direction = lastDirection; + } + } + lastDirection = direction; + WRITE_UINT16(tempDirTab, direction); + tempDirTab += 2; + } + // finito + int end = *(tempDirTab - 1); + WRITE_UINT16(tempDirTab, end); + tempDirTab += 2; + WRITE_UINT16(tempDirTab, 0); + tempDirTab += 2; + } } // TODO diff --git a/engines/prince/prince.h b/engines/prince/prince.h index 89c24ec0a5..7a6596ada6 100644 --- a/engines/prince/prince.h +++ b/engines/prince/prince.h @@ -500,7 +500,9 @@ public: static void plotTracePoint(int x, int y, int color, void *data); void specialPlotInside2(int x, int y); void approxPath(); + void freeDirectionTable(); void scanDirections(); + int scanDirectionsFindNext(byte *coords, int xDiff, int yDiff); void moveShandria(); void testDrawPath(); |