diff options
author | Max Horn | 2002-12-29 21:14:28 +0000 |
---|---|---|
committer | Max Horn | 2002-12-29 21:14:28 +0000 |
commit | 5f472bdcd031c843dfec78c014fdf97370dc5768 (patch) | |
tree | c8de0a8f0419dbede799d14333f9850ce5d183da | |
parent | ceac475714a41766464ffe18a3c538c8c32a18aa (diff) | |
download | scummvm-rg350-5f472bdcd031c843dfec78c014fdf97370dc5768.tar.gz scummvm-rg350-5f472bdcd031c843dfec78c014fdf97370dc5768.tar.bz2 scummvm-rg350-5f472bdcd031c843dfec78c014fdf97370dc5768.zip |
cleanup
svn-id: r6263
-rw-r--r-- | scumm/boxes.cpp | 86 | ||||
-rw-r--r-- | scumm/scumm.h | 2 |
2 files changed, 42 insertions, 46 deletions
diff --git a/scumm/boxes.cpp b/scumm/boxes.cpp index b0cc3efb27..4ccec1ea65 100644 --- a/scumm/boxes.cpp +++ b/scumm/boxes.cpp @@ -419,7 +419,7 @@ int Scumm::getPathToDestBox(byte from, byte to) } while (boxm[0] != 0xFF) { - if (boxm[0] <= to && boxm[1] >= to) + if (boxm[0] <= to && to <= boxm[1]) dest = boxm[2]; boxm += 3; } @@ -566,32 +566,32 @@ bool Scumm::findPathTowards(Actor *a, byte box1nr, byte box2nr, byte box3nr, int void Scumm::createBoxMatrix() { - byte *matrix_ptr; int num, i, j; byte flags; int table_1[66], table_2[66]; int counter, val; int code; - PathVertex *vtx; - PathNode *node, *node2 = NULL; + // A heap (an optiimsation to avoid calling malloc/free extremly often) _maxBoxVertexHeap = 1000; - - createResource(rtMatrix, 4, 1000); - createResource(rtMatrix, 3, 4160); //65 items of something of size 64 + createResource(rtMatrix, 4, _maxBoxVertexHeap); + _boxPathVertexHeap = getResourceAddress(rtMatrix, 4); + _boxPathVertexHeapIndex = 1; + + // Temporary 64*65 distance matrix + createResource(rtMatrix, 3, 65 * 64); + _boxMatrixPtr3 = getResourceAddress(rtMatrix, 3); + + // The result "matrix" in the special format used by Scumm. createResource(rtMatrix, 1, BOX_MATRIX_SIZE); - - matrix_ptr = getResourceAddress(rtMatrix, 1); - - _boxMatrixPtr4 = getResourceAddress(rtMatrix, 4); _boxMatrixPtr1 = getResourceAddress(rtMatrix, 1); - _boxMatrixPtr3 = getResourceAddress(rtMatrix, 3); - - _boxPathVertexHeapIndex = _boxMatrixItem = 0; num = getNumBoxes(); + // Initialise the distance matrix: each box has distance 0 to itself, + // and distance 1 to its direct neighbors. Initially, it has distance + // 250 (= infinity) to all other boxes. for (i = 0; i < num; i++) { for (j = 0; j < num; j++) { if (i == j) { @@ -604,15 +604,18 @@ void Scumm::createBoxMatrix() } } + // Iterate over all boxes for (j = 0; j < num; j++) { flags = getBoxFlags(j); if (flags & kBoxInvisible) { + // Locked/invisible boxes are only reachable from themselves. addToBoxMatrix(0xFF); addToBoxMatrix(j); addToBoxMatrix(j); addToBoxMatrix(j); } else { - vtx = addPathVertex(); + PathNode *node, *node2 = NULL; + PathVertex *vtx = addPathVertex(); for (i = 0; i < num; i++) { flags = getBoxFlags(j); if (!(flags & kBoxInvisible)) { @@ -666,27 +669,23 @@ void Scumm::createBoxMatrix() } addToBoxMatrix(0xFF); - for (i = 1; i < num;) { + for (i = 1; i < num; i++) { if (table_2[i - 1] != -1) { addToBoxMatrix(i - 1); /* lo */ - if (table_2[i - 1] != table_2[i]) { - addToBoxMatrix(i - 1); /* hi */ - addToBoxMatrix(table_2[i - 1]); /* dst */ - } else { - while (table_2[i - 1] == table_2[i]) { - if (++i == num) - break; - } - addToBoxMatrix(i - 1); /* hi */ - addToBoxMatrix(table_2[i - 1]); /* dst */ + while (table_2[i - 1] == table_2[i]) { + ++i; + if (i == num) + break; } - } - if (++i == num && table_2[i - 1] != -1) { - addToBoxMatrix(i - 1); /* lo */ addToBoxMatrix(i - 1); /* hi */ - addToBoxMatrix(table_2[i - 1]); /* dest */ + addToBoxMatrix(table_2[i - 1]); /* dst */ } } + if (i == num && table_2[i - 1] != -1) { + addToBoxMatrix(i - 1); /* lo */ + addToBoxMatrix(i - 1); /* hi */ + addToBoxMatrix(table_2[i - 1]); /* dest */ + } } } @@ -725,27 +724,24 @@ PathNode *Scumm::unkMatrixProc2(PathVertex *vtx, int i) if (vtx == NULL) return NULL; - if (!vtx->right) { - node = (PathNode *)addToBoxVertexHeap(sizeof(PathNode)); - vtx->left = vtx->right = node; + node = (PathNode *)addToBoxVertexHeap(sizeof(PathNode)); + node->index = i; + node->left = 0; + node->right = 0; - node->index = i; - node->left = 0; - node->right = 0; + if (!vtx->right) { + vtx->left = node; } else { - node = (PathNode *)addToBoxVertexHeap(sizeof(PathNode)); vtx->right->left = node; - node->right = vtx->right; - node->index = i; - node->left = 0; - - vtx->right = node; } + vtx->right = node; + return vtx->right; } + /* Check if two boxes are neighbours */ bool Scumm::areBoxesNeighbours(int box1nr, int box2nr) { @@ -866,9 +862,9 @@ void Scumm::addToBoxMatrix(byte b) void *Scumm::addToBoxVertexHeap(int size) { - byte *ptr = _boxMatrixPtr4; + byte *ptr = _boxPathVertexHeap; - _boxMatrixPtr4 += size; + _boxPathVertexHeap += size; _boxPathVertexHeapIndex += size; if (_boxPathVertexHeapIndex >= _maxBoxVertexHeap) @@ -879,7 +875,7 @@ void *Scumm::addToBoxVertexHeap(int size) PathVertex *Scumm::addPathVertex() { - _boxMatrixPtr4 = getResourceAddress(rtMatrix, 4); + _boxPathVertexHeap = getResourceAddress(rtMatrix, 4); _boxPathVertexHeapIndex = 0; return (PathVertex *)addToBoxVertexHeap(sizeof(PathVertex)); diff --git a/scumm/scumm.h b/scumm/scumm.h index 2d24efbc5d..78b3e9c5c2 100644 --- a/scumm/scumm.h +++ b/scumm/scumm.h @@ -846,7 +846,7 @@ public: /* Walkbox / Navigation class */ int _maxBoxVertexHeap, _boxPathVertexHeapIndex, _boxMatrixItem; - byte *_boxMatrixPtr4, *_boxMatrixPtr1, *_boxMatrixPtr3; + byte *_boxPathVertexHeap, *_boxMatrixPtr1, *_boxMatrixPtr3; uint16 _extraBoxFlags[65]; |