mirror of
https://github.com/RTimothyEdwards/magic.git
synced 2026-08-22 14:17:43 +02:00
Applied the same change made yesterday to DBconnect.c to ResConDCS.c
and SimDBstuff.c, which have nearly the same connectivity search functions. All three now use the hybrid list + stack method.
This commit is contained in:
+38
-18
@@ -31,6 +31,7 @@
|
||||
#include "utils/geofast.h"
|
||||
#include "tiles/tile.h"
|
||||
#include "utils/hash.h"
|
||||
#include "utils/stack.h"
|
||||
#include "database/database.h"
|
||||
#include "database/databaseInt.h"
|
||||
#include "textio/textio.h"
|
||||
@@ -86,12 +87,13 @@ struct conSrArg2
|
||||
*/
|
||||
Rect *csa2_bounds; /* Area that limits the search */
|
||||
|
||||
Stack *csa2_stack; /* Stack of full csa2_list entries */
|
||||
conSrArea *csa2_list; /* List of areas to process */
|
||||
int csa2_top; /* Index of next area to process */
|
||||
int csa2_size; /* Max. number bins in area list */
|
||||
int csa2_lasttop; /* Previous top index */
|
||||
};
|
||||
|
||||
#define CSA2_LIST_START_SIZE 256
|
||||
#define CSA2_LIST_SIZE 65536 /* Number of entries per list */
|
||||
|
||||
/* Forward declarations */
|
||||
|
||||
@@ -303,27 +305,29 @@ SimConnectFunc(tile, cx)
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Check if any of the last 5 entries has the same type and */
|
||||
/* area. If so, don't duplicate the existing entry. */
|
||||
/* (NOTE: Connect masks are all from the same table, so */
|
||||
/* they can be compared by address, no need for TTMaskEqual)*/
|
||||
|
||||
for (i = csa2->csa2_lasttop; (i >= 0) && (i > csa2->csa2_lasttop - 5); i--)
|
||||
if (connectMask == csa2->csa2_list[i].connectMask)
|
||||
if (GEO_SURROUND(&csa2->csa2_list[i].area, &newarea))
|
||||
return 0;
|
||||
|
||||
/* Register the area and connection mask as needing to be processed */
|
||||
|
||||
if (++csa2->csa2_top == csa2->csa2_size)
|
||||
if (++csa2->csa2_top == CSA2_LIST_SIZE)
|
||||
{
|
||||
/* Reached list size limit---need to enlarge the list */
|
||||
/* Double the size of the list every time we hit the limit */
|
||||
|
||||
conSrArea *newlist;
|
||||
int i, lastsize = csa2->csa2_size;
|
||||
|
||||
csa2->csa2_size *= 2;
|
||||
|
||||
newlist = (conSrArea *)mallocMagic(csa2->csa2_size * sizeof(conSrArea));
|
||||
for (i = 0; i < lastsize; i++)
|
||||
{
|
||||
newlist[i].area = csa2->csa2_list[i].area;
|
||||
newlist[i].connectMask = csa2->csa2_list[i].connectMask;
|
||||
newlist[i].dinfo = csa2->csa2_list[i].dinfo;
|
||||
}
|
||||
freeMagic((char *)csa2->csa2_list);
|
||||
newlist = (conSrArea *)mallocMagic(CSA2_LIST_SIZE * sizeof(conSrArea));
|
||||
StackPush((ClientData)csa2->csa2_list, csa2->csa2_stack);
|
||||
csa2->csa2_list = newlist;
|
||||
csa2->csa2_top = 0;
|
||||
}
|
||||
|
||||
csa2->csa2_list[csa2->csa2_top].area = newarea;
|
||||
@@ -407,10 +411,11 @@ SimTreeCopyConnect(scx, mask, xMask, connect, area, destUse, Node_Name)
|
||||
csa2.csa2_bounds = area;
|
||||
csa2.csa2_connect = connect;
|
||||
|
||||
csa2.csa2_size = CSA2_LIST_START_SIZE;
|
||||
csa2.csa2_list = (conSrArea *)mallocMagic(CSA2_LIST_START_SIZE
|
||||
* sizeof(conSrArea));
|
||||
csa2.csa2_list = (conSrArea *)mallocMagic(CSA2_LIST_SIZE * sizeof(conSrArea));
|
||||
csa2.csa2_top = -1;
|
||||
csa2.csa2_lasttop = -1;
|
||||
|
||||
csa2.csa2_stack = StackNew(100);
|
||||
|
||||
tpath.tp_first = tpath.tp_next = pathName;
|
||||
tpath.tp_last = pathName + MAXPATHNAME;
|
||||
@@ -425,7 +430,21 @@ SimTreeCopyConnect(scx, mask, xMask, connect, area, destUse, Node_Name)
|
||||
newmask = csa2.csa2_list[csa2.csa2_top].connectMask;
|
||||
scx->scx_area = csa2.csa2_list[csa2.csa2_top].area;
|
||||
newtype = csa2.csa2_list[csa2.csa2_top].dinfo;
|
||||
csa2.csa2_top--;
|
||||
if (csa2.csa2_top == 0)
|
||||
{
|
||||
if (StckLook(csa2.csa2_stack) != (ClientData)NULL)
|
||||
{
|
||||
freeMagic(csa2.csa2_list);
|
||||
csa2.csa2_list = (conSrArea *)StackPop(csa2.csa2_stack);
|
||||
csa2.csa2_top = CSA2_LIST_SIZE - 1;
|
||||
}
|
||||
else
|
||||
csa2.csa2_top--;
|
||||
}
|
||||
else
|
||||
csa2.csa2_top--;
|
||||
|
||||
csa2.csa2_lasttop = csa2.csa2_top;
|
||||
|
||||
if (newtype & TT_DIAGONAL)
|
||||
SimTreeSrNMTiles(scx, newtype, newmask, xMask, &tpath,
|
||||
@@ -435,6 +454,7 @@ SimTreeCopyConnect(scx, mask, xMask, connect, area, destUse, Node_Name)
|
||||
(ClientData) &csa2);
|
||||
}
|
||||
freeMagic((char *)csa2.csa2_list);
|
||||
StackFree(csa2.csa2_stack);
|
||||
|
||||
/* Recompute the bounding box of the destination and record
|
||||
* its area for redisplay.
|
||||
|
||||
Reference in New Issue
Block a user