tilepacker.cpp: instead of maintaining the heap on each insertion, maxheap_buildHeap() on tilepacker_pack()

git-svn-id: https://svn.eduke32.com/eduke32@6918 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
pogokeen 2018-06-13 19:15:10 +00:00
parent 58132c2353
commit 38de24d7eb

View file

@ -33,6 +33,7 @@ TreeNode rejectQueue[MAX_REJECTS];
uint32_t rejectQueueHeadIndex = 0;
uint32_t numRejected = 0;
#if 0
static void maxheap_bubbleUp(uint32_t nodeIndex)
{
while (true)
@ -56,6 +57,7 @@ static void maxheap_bubbleUp(uint32_t nodeIndex)
nodeIndex = parentIndex;
}
}
#endif
static void maxheap_bubbleDown(uint32_t nodeIndex)
{
@ -88,6 +90,14 @@ static void maxheap_bubbleDown(uint32_t nodeIndex)
}
}
static void maxheap_buildHeap()
{
for (int i = (heapNodes-2)/2; i >= 0; --i)
{
maxheap_bubbleDown(i);
}
}
static TreeNode* maxheap_pop()
{
if (heapNodes == 0)
@ -300,7 +310,6 @@ void tilepacker_addTile(uint32_t tileUID, uint32_t tileWidth, uint32_t tileHeigh
(TreeNode*) 0,
{0, 0, tileWidth, tileHeight},
tileUID);
maxheap_bubbleUp(heapNodes-1);
}
char tilepacker_pack(uint32_t tilesheetID)
@ -319,6 +328,8 @@ char tilepacker_pack(uint32_t tilesheetID)
rejectQueue_add(pNode);
}
}
maxheap_buildHeap();
for (TreeNode *pNode = maxheap_pop(); pNode != NULL; pNode = maxheap_pop())
{
char success = kdtree_add(tilesheetID, pNode);