hey,
The code goes through several loops, reading from the file, rewinding, reading again - to me most of this seems totally unnecessary but it sets up several variables in the process, including the vertice array, and i didn't want to mess with it until i understood it better.
Adding some TRACE lines after each loop and at other points showed that most of the code took less than a second to complete (which suprised me)
The bottleneck is on the very last loop where (i think) all of the BSP calculations are done, but like i say this part is totally beyond me !!
Code:
for (Pnr=minvertnr;Pnr<=maxvertnr;Pnr++) {
ptr=V[Pnr].connect;
if (ptr==&dummy || ptr==NULL) continue;
Ps=V[Pnr].VT;
///////////////////////////////////////////////////////////
for (iconnect=1;iconnect<=*ptr;iconnect++) {
Qnr=ptr[iconnect];Qs=V[Qnr].VT;
if (Ps.X<Qs.X || (Ps.X==Qs.X && Ps.Y < Qs.Y))
{Left=Ps;Right=Qs;}
else
{Left=Qs;Right=Ps;}
ileft=colnr(Left.X);iright=colnr(Right.X);
if (ileft != iright) {deltay=Right.Y-Left.Y;deltax=Right.X-Left.X;}
jbot=jtop=rownr(Left.Y);
for (I=ileft;I<=iright;I++) {
jI= (I == iright ? rownr(Right.Y) : rownr(Left.Y+(Xcoord(I+1)-Left.X) * deltay/deltax));
LOWER[I]=min2(jbot,jI);jbot=jI;
UPPER[I]=max2(jtop,jI);jtop=jI;
}
ntrset=0;
///////////////////////////////////////////////////////////
for (I=ileft;I<=iright;I++) {
for (J=LOWER[I];J<=UPPER[I];J++) {
pnode=SCREEN[I][J];
while (pnode!=NULL) {
trnr=pnode->jtr;
trset[ntrset]=trnr;
jtr=0;
while (trset[jtr] !=trnr) jtr++;
if (jtr==ntrset) {
ntrset++;
if (ntrset==maxntrset) {
int *p=trset;
trset=new int[maxntrset+=10];
if (!trset) errmess("can't add more triangles to sets"); //maxntrset
for (int i=0;i<ntrset;i++) trset[i]=p[i];
delete [] p;p=NULL;
}
}
pnode=pnode->next;
}
}
}
///////////////////////////////////////////////////////////
linesegment(hpoint(Ps,V[Pnr].z,Pnr),hpoint(Qs,V[Qnr].z,Qnr),ntrset);
dealwithlinkedstack();
}
Instead of drawing directly to the DC i did create an array of lines first and then dump this array to the DC. Refreshing the view was (almost) instant.
I have an array of polygons inside a Model Class that i loop through, rotate each point (x,y,z) and draw a line to the DC to create a simple (see through) design view, which is extremely fast.
I then had to dump these points to a file to test this HiddenLine function. (so reading from a file is not really necessary but i'm not good enough to make it use my polygons directly)