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:
parent
f7820ed960
commit
c2aedcebab
|
|
@ -84,7 +84,6 @@ struct conSrArg2
|
||||||
* to what.
|
* to what.
|
||||||
*/
|
*/
|
||||||
SearchContext *csa2_topscx; /* Original top-level search context */
|
SearchContext *csa2_topscx; /* Original top-level search context */
|
||||||
int csa2_xMask; /* Cell window mask for search */
|
|
||||||
Rect *csa2_bounds; /* Area that limits the search */
|
Rect *csa2_bounds; /* Area that limits the search */
|
||||||
|
|
||||||
Stack *csa2_stack; /* Stack of full csa2_list entries */
|
Stack *csa2_stack; /* Stack of full csa2_list entries */
|
||||||
|
|
@ -1053,7 +1052,6 @@ DBTreeCopyConnect(scx, mask, xMask, connect, area, doLabels, destUse)
|
||||||
unsigned char searchtype;
|
unsigned char searchtype;
|
||||||
|
|
||||||
csa2.csa2_use = destUse;
|
csa2.csa2_use = destUse;
|
||||||
csa2.csa2_xMask = xMask;
|
|
||||||
csa2.csa2_bounds = area;
|
csa2.csa2_bounds = area;
|
||||||
csa2.csa2_connect = connect;
|
csa2.csa2_connect = connect;
|
||||||
csa2.csa2_topscx = scx;
|
csa2.csa2_topscx = scx;
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ static char rcsid[] __attribute__ ((unused)) = "$Header: /usr/cvsroot/magic-8.0/
|
||||||
#include "utils/geofast.h"
|
#include "utils/geofast.h"
|
||||||
#include "tiles/tile.h"
|
#include "tiles/tile.h"
|
||||||
#include "utils/hash.h"
|
#include "utils/hash.h"
|
||||||
|
#include "utils/stack.h"
|
||||||
#include "database/database.h"
|
#include "database/database.h"
|
||||||
#include "utils/malloc.h"
|
#include "utils/malloc.h"
|
||||||
#include "textio/textio.h"
|
#include "textio/textio.h"
|
||||||
|
|
@ -46,12 +47,13 @@ struct conSrArg2
|
||||||
int csa2_xMask; /* Cell window mask for search */
|
int csa2_xMask; /* Cell window mask for search */
|
||||||
Rect *csa2_bounds; /* Area that limits the search */
|
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 */
|
conSrArea *csa2_list; /* List of areas to process */
|
||||||
int csa2_top; /* Index of next area 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 */
|
||||||
|
|
||||||
extern int dbcUnconnectFunc();
|
extern int dbcUnconnectFunc();
|
||||||
extern int dbcConnectLabelFunc();
|
extern int dbcConnectLabelFunc();
|
||||||
|
|
@ -100,7 +102,7 @@ dbcConnectFuncDCS(tile, cx)
|
||||||
TileType dinfo = 0;
|
TileType dinfo = 0;
|
||||||
SearchContext *scx = cx->tc_scx;
|
SearchContext *scx = cx->tc_scx;
|
||||||
SearchContext scx2;
|
SearchContext scx2;
|
||||||
int pNum;
|
int i, pNum;
|
||||||
CellDef *def;
|
CellDef *def;
|
||||||
ExtDevice *devptr;
|
ExtDevice *devptr;
|
||||||
TerminalPath tpath;
|
TerminalPath tpath;
|
||||||
|
|
@ -296,29 +298,29 @@ dbcConnectFuncDCS(tile, cx)
|
||||||
newarea.r_ytop += 1;
|
newarea.r_ytop += 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 */
|
/* 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 */
|
/* Reached list size limit---need to enlarge the list */
|
||||||
/* Double the size of the list every time we hit the limit */
|
/* Double the size of the list every time we hit the limit */
|
||||||
|
|
||||||
conSrArea *newlist;
|
conSrArea *newlist;
|
||||||
int i, lastsize = csa2->csa2_size;
|
|
||||||
|
|
||||||
csa2->csa2_size *= 2;
|
newlist = (conSrArea *)mallocMagic(CSA2_LIST_SIZE * sizeof(conSrArea));
|
||||||
|
StackPush((ClientData)csa2->csa2_list, csa2->csa2_stack);
|
||||||
newlist = (conSrArea *)mallocMagic(csa2->csa2_size * sizeof(conSrArea));
|
|
||||||
memcpy((void *)newlist, (void *)csa2->csa2_list,
|
|
||||||
(size_t)lastsize * 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);
|
|
||||||
csa2->csa2_list = newlist;
|
csa2->csa2_list = newlist;
|
||||||
|
csa2->csa2_top = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
csa2->csa2_list[csa2->csa2_top].area = newarea;
|
csa2->csa2_list[csa2->csa2_top].area = newarea;
|
||||||
|
|
@ -443,10 +445,11 @@ DBTreeCopyConnectDCS(scx, mask, xMask, connect, area, destUse)
|
||||||
csa2.csa2_connect = connect;
|
csa2.csa2_connect = connect;
|
||||||
csa2.csa2_topscx = scx;
|
csa2.csa2_topscx = scx;
|
||||||
|
|
||||||
csa2.csa2_size = CSA2_LIST_START_SIZE;
|
csa2.csa2_list = (conSrArea *)mallocMagic(CSA2_LIST_SIZE * sizeof(conSrArea));
|
||||||
csa2.csa2_list = (conSrArea *)mallocMagic(CSA2_LIST_START_SIZE
|
|
||||||
* sizeof(conSrArea));
|
|
||||||
csa2.csa2_top = -1;
|
csa2.csa2_top = -1;
|
||||||
|
csa2.csa2_lasttop = -1;
|
||||||
|
|
||||||
|
csa2.csa2_stack = StackNew(100);
|
||||||
|
|
||||||
if (first)
|
if (first)
|
||||||
{
|
{
|
||||||
|
|
@ -474,7 +477,22 @@ DBTreeCopyConnectDCS(scx, mask, xMask, connect, area, destUse)
|
||||||
newmask = csa2.csa2_list[csa2.csa2_top].connectMask;
|
newmask = csa2.csa2_list[csa2.csa2_top].connectMask;
|
||||||
scx->scx_area = csa2.csa2_list[csa2.csa2_top].area;
|
scx->scx_area = csa2.csa2_list[csa2.csa2_top].area;
|
||||||
newtype = csa2.csa2_list[csa2.csa2_top].dinfo;
|
newtype = csa2.csa2_list[csa2.csa2_top].dinfo;
|
||||||
|
if (csa2.csa2_top == 0)
|
||||||
|
{
|
||||||
|
if (StackLook(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--;
|
csa2.csa2_top--;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
csa2.csa2_top--;
|
||||||
|
|
||||||
|
csa2.csa2_lasttop = csa2.csa2_top;
|
||||||
|
|
||||||
if (newtype & TT_DIAGONAL)
|
if (newtype & TT_DIAGONAL)
|
||||||
DBTreeSrNMTiles(scx, newtype, newmask, xMask, dbcConnectFuncDCS,
|
DBTreeSrNMTiles(scx, newtype, newmask, xMask, dbcConnectFuncDCS,
|
||||||
(ClientData) &csa2);
|
(ClientData) &csa2);
|
||||||
|
|
@ -482,6 +500,7 @@ DBTreeCopyConnectDCS(scx, mask, xMask, connect, area, destUse)
|
||||||
DBTreeSrTiles(scx, newmask, xMask, dbcConnectFuncDCS, (ClientData) &csa2);
|
DBTreeSrTiles(scx, newmask, xMask, dbcConnectFuncDCS, (ClientData) &csa2);
|
||||||
}
|
}
|
||||||
freeMagic((char *)csa2.csa2_list);
|
freeMagic((char *)csa2.csa2_list);
|
||||||
|
StackFree(csa2.csa2_stack);
|
||||||
|
|
||||||
for (CurrentT = DevList; CurrentT != NULL; CurrentT=CurrentT->nextDev)
|
for (CurrentT = DevList; CurrentT != NULL; CurrentT=CurrentT->nextDev)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@
|
||||||
#include "utils/geofast.h"
|
#include "utils/geofast.h"
|
||||||
#include "tiles/tile.h"
|
#include "tiles/tile.h"
|
||||||
#include "utils/hash.h"
|
#include "utils/hash.h"
|
||||||
|
#include "utils/stack.h"
|
||||||
#include "database/database.h"
|
#include "database/database.h"
|
||||||
#include "database/databaseInt.h"
|
#include "database/databaseInt.h"
|
||||||
#include "textio/textio.h"
|
#include "textio/textio.h"
|
||||||
|
|
@ -86,12 +87,13 @@ struct conSrArg2
|
||||||
*/
|
*/
|
||||||
Rect *csa2_bounds; /* Area that limits the search */
|
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 */
|
conSrArea *csa2_list; /* List of areas to process */
|
||||||
int csa2_top; /* Index of next area 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 */
|
/* Forward declarations */
|
||||||
|
|
||||||
|
|
@ -303,27 +305,29 @@ SimConnectFunc(tile, cx)
|
||||||
return 1;
|
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 */
|
/* 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 */
|
/* Reached list size limit---need to enlarge the list */
|
||||||
/* Double the size of the list every time we hit the limit */
|
/* Double the size of the list every time we hit the limit */
|
||||||
|
|
||||||
conSrArea *newlist;
|
conSrArea *newlist;
|
||||||
int i, lastsize = csa2->csa2_size;
|
|
||||||
|
|
||||||
csa2->csa2_size *= 2;
|
newlist = (conSrArea *)mallocMagic(CSA2_LIST_SIZE * sizeof(conSrArea));
|
||||||
|
StackPush((ClientData)csa2->csa2_list, csa2->csa2_stack);
|
||||||
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);
|
|
||||||
csa2->csa2_list = newlist;
|
csa2->csa2_list = newlist;
|
||||||
|
csa2->csa2_top = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
csa2->csa2_list[csa2->csa2_top].area = newarea;
|
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_bounds = area;
|
||||||
csa2.csa2_connect = connect;
|
csa2.csa2_connect = connect;
|
||||||
|
|
||||||
csa2.csa2_size = CSA2_LIST_START_SIZE;
|
csa2.csa2_list = (conSrArea *)mallocMagic(CSA2_LIST_SIZE * sizeof(conSrArea));
|
||||||
csa2.csa2_list = (conSrArea *)mallocMagic(CSA2_LIST_START_SIZE
|
|
||||||
* sizeof(conSrArea));
|
|
||||||
csa2.csa2_top = -1;
|
csa2.csa2_top = -1;
|
||||||
|
csa2.csa2_lasttop = -1;
|
||||||
|
|
||||||
|
csa2.csa2_stack = StackNew(100);
|
||||||
|
|
||||||
tpath.tp_first = tpath.tp_next = pathName;
|
tpath.tp_first = tpath.tp_next = pathName;
|
||||||
tpath.tp_last = pathName + MAXPATHNAME;
|
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;
|
newmask = csa2.csa2_list[csa2.csa2_top].connectMask;
|
||||||
scx->scx_area = csa2.csa2_list[csa2.csa2_top].area;
|
scx->scx_area = csa2.csa2_list[csa2.csa2_top].area;
|
||||||
newtype = csa2.csa2_list[csa2.csa2_top].dinfo;
|
newtype = csa2.csa2_list[csa2.csa2_top].dinfo;
|
||||||
|
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--;
|
csa2.csa2_top--;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
csa2.csa2_top--;
|
||||||
|
|
||||||
|
csa2.csa2_lasttop = csa2.csa2_top;
|
||||||
|
|
||||||
if (newtype & TT_DIAGONAL)
|
if (newtype & TT_DIAGONAL)
|
||||||
SimTreeSrNMTiles(scx, newtype, newmask, xMask, &tpath,
|
SimTreeSrNMTiles(scx, newtype, newmask, xMask, &tpath,
|
||||||
|
|
@ -435,6 +454,7 @@ SimTreeCopyConnect(scx, mask, xMask, connect, area, destUse, Node_Name)
|
||||||
(ClientData) &csa2);
|
(ClientData) &csa2);
|
||||||
}
|
}
|
||||||
freeMagic((char *)csa2.csa2_list);
|
freeMagic((char *)csa2.csa2_list);
|
||||||
|
StackFree(csa2.csa2_stack);
|
||||||
|
|
||||||
/* Recompute the bounding box of the destination and record
|
/* Recompute the bounding box of the destination and record
|
||||||
* its area for redisplay.
|
* its area for redisplay.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue