diff options
author | Eugene Sandulenko | 2011-08-14 05:23:01 -0700 |
---|---|---|
committer | Eugene Sandulenko | 2011-08-14 05:23:01 -0700 |
commit | 913e15db5874692f2bd8bf3e27a8d1813c84605f (patch) | |
tree | 7b860f81dc1f5ea9437eb1f5e4af4d3c30e8a889 | |
parent | dfcefb3c2231c46eba3c4ac5cd24ef09cb8b17d1 (diff) | |
parent | a7e49f294502c4c2efa2b37eb2c5b0ae3d1b66f7 (diff) | |
download | scummvm-rg350-913e15db5874692f2bd8bf3e27a8d1813c84605f.tar.gz scummvm-rg350-913e15db5874692f2bd8bf3e27a8d1813c84605f.tar.bz2 scummvm-rg350-913e15db5874692f2bd8bf3e27a8d1813c84605f.zip |
Merge pull request #56 from zeldin/toon-path-dynamic
TOON: Grow size of path finding heap dynamically
-rw-r--r-- | engines/toon/path.cpp | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/engines/toon/path.cpp b/engines/toon/path.cpp index 785b84a78e..60ca007930 100644 --- a/engines/toon/path.cpp +++ b/engines/toon/path.cpp @@ -33,15 +33,15 @@ PathFindingHeap::PathFindingHeap() { } PathFindingHeap::~PathFindingHeap() { - delete[] _data; + free(_data); } void PathFindingHeap::init(int32 size) { debugC(1, kDebugPath, "init(%d)", size); _size = size; - delete[] _data; - _data = new HeapDataGrid[_size]; + free(_data); + _data = (HeapDataGrid *)malloc(sizeof(HeapDataGrid) * _size); memset(_data, 0, sizeof(HeapDataGrid) * _size); _count = 0; } @@ -49,7 +49,7 @@ void PathFindingHeap::init(int32 size) { void PathFindingHeap::unload() { _count = 0; _size = 0; - delete[] _data; + free(_data); _data = NULL; } @@ -64,8 +64,19 @@ void PathFindingHeap::push(int32 x, int32 y, int32 weight) { debugC(2, kDebugPath, "push(%d, %d, %d)", x, y, weight); if (_count == _size) { - warning("Aborting attempt to push onto PathFindingHeap at maximum size: %d", _count); - return; + // Increase size by 50% + int newSize = _size + (_size >> 1) + 1; + HeapDataGrid *newData; + + newData = (HeapDataGrid *)realloc(_data, sizeof(HeapDataGrid) * newSize); + if (newData == NULL) { + warning("Aborting attempt to push onto PathFindingHeap at maximum size: %d", _count); + return; + } + + memset(newData + _size, 0, sizeof(HeapDataGrid) * (newSize - _size)); + _data = newData; + _size = newSize; } _data[_count]._x = x; @@ -427,11 +438,7 @@ void PathFinding::init(Picture *mask) { _height = mask->getHeight(); _currentMask = mask; _heap->unload(); - // In order to reduce memory fragmentation on small devices, we use the maximum - // possible size here which is TOON_BACKBUFFER_WIDTH. Even though this is - // 1280 as opposed to the possible 640, it actually helps memory allocation on - // those devices. - _heap->init(TOON_BACKBUFFER_WIDTH * _height); // should really be _width + _heap->init(500); delete[] _gridTemp; _gridTemp = new int32[_width*_height]; } |