mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2026-02-04 04:36:21 +00:00
Merge branch 'pathfind-realloc-fix' into 'master'
Pathfinding reallocation fix See merge request KartKrew/Kart!290
This commit is contained in:
commit
47a7c285de
2 changed files with 37 additions and 2 deletions
|
|
@ -469,6 +469,10 @@ boolean K_BHeapPop(bheap_t *const heap, bheapitem_t *const returnitemstorage)
|
|||
heap->array[0] = heap->array[heap->count];
|
||||
heap->array[0].heapindex = 0U;
|
||||
memset(&heap->array[heap->count], 0x00, sizeof(bheapitem_t));
|
||||
if (heap->array[0].indexchanged != NULL)
|
||||
{
|
||||
heap->array[0].indexchanged(heap->array[0].data, heap->array[0].heapindex);
|
||||
}
|
||||
|
||||
K_BHeapSortDown(heap, &heap->array[0]);
|
||||
popsuccess = true;
|
||||
|
|
|
|||
|
|
@ -472,13 +472,44 @@ boolean K_PathfindAStar(path_t *const path, pathfindsetup_t *const pathfindsetup
|
|||
// Reallocate nodesarray if it's full
|
||||
if (nodesarraycount >= pathfindsetup->nodesarraycapacity)
|
||||
{
|
||||
pathfindnode_t *nodesarrayrealloc = NULL;
|
||||
pathfindsetup->nodesarraycapacity = pathfindsetup->nodesarraycapacity * 2;
|
||||
nodesarray = Z_Realloc(nodesarray, pathfindsetup->nodesarraycapacity * sizeof(pathfindnode_t), PU_STATIC, NULL);
|
||||
nodesarrayrealloc = Z_Realloc(nodesarray, pathfindsetup->nodesarraycapacity * sizeof(pathfindnode_t), PU_STATIC, NULL);
|
||||
|
||||
if (nodesarray == NULL)
|
||||
if (nodesarrayrealloc == NULL)
|
||||
{
|
||||
I_Error("K_PathfindAStar: Out of memory reallocating nodes array.");
|
||||
}
|
||||
|
||||
// Need to update pointers in closedset, openset, and node "camefrom" if nodesarray moved.
|
||||
if (nodesarray != nodesarrayrealloc)
|
||||
{
|
||||
size_t i = 0U;
|
||||
size_t arrayindex = 0U;
|
||||
for (i = 0U; i < closedsetcount; i++)
|
||||
{
|
||||
arrayindex = closedset[i] - nodesarray;
|
||||
closedset[i] = &nodesarrayrealloc[arrayindex];
|
||||
}
|
||||
for (i = 0U; i < openset.count; i++)
|
||||
{
|
||||
arrayindex = ((pathfindnode_t *)(openset.array[i].data)) - nodesarray;
|
||||
openset.array[i].data = &nodesarrayrealloc[arrayindex];
|
||||
}
|
||||
for (i = 0U; i < nodesarraycount; i++)
|
||||
{
|
||||
if (nodesarrayrealloc[i].camefrom != NULL)
|
||||
{
|
||||
arrayindex = nodesarrayrealloc[i].camefrom - nodesarray;
|
||||
nodesarrayrealloc[i].camefrom = &nodesarrayrealloc[arrayindex];
|
||||
}
|
||||
}
|
||||
|
||||
arrayindex = currentnode - nodesarray;
|
||||
currentnode = &nodesarrayrealloc[arrayindex];
|
||||
}
|
||||
|
||||
nodesarray = nodesarrayrealloc;
|
||||
}
|
||||
|
||||
// Create the new node and add it to the nodes array and open set
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue