ref: d232666db505777632319791d6a9dd78f2cd1e50
parent: 388ac5e22b561fec0acae369f3ec21c4be9a9f99
parent: 61a0ad733e08c9a03a7ee5e1db2c72e19a7a05e8
author: fabien sanglard <[email protected]>
date: Thu Jan 31 19:25:36 EST 2013
Merge branch 'master' of github.com:fabiensanglard/chocolate_duke3D
--- a/Engine/Engine.vcxproj
+++ b/Engine/Engine.vcxproj
@@ -100,9 +100,9 @@
<ClCompile Include="src\draw.c" />
<ClCompile Include="src\Engine.c" />
<ClCompile Include="src\filesystem.c" />
+ <ClCompile Include="src\fixedPoint_math.c" />
<ClCompile Include="src\mmulti.c" />
<ClCompile Include="src\mmulti_stable.cpp" />
- <ClCompile Include="src\pragmas.c" />
<ClCompile Include="src\enet\host.c" />
<ClCompile Include="src\enet\list.c" />
<ClCompile Include="src\enet\memory.c" />
@@ -111,6 +111,8 @@
<ClCompile Include="src\enet\protocol.c" />
<ClCompile Include="src\enet\unix.c" />
<ClCompile Include="src\enet\win32.c" />
+ <ClCompile Include="src\network.c" />
+ <ClCompile Include="src\tiles.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\build.h" />
@@ -119,9 +121,11 @@
<ClInclude Include="src\draw.h" />
<ClInclude Include="src\Engine.h" />
<ClInclude Include="src\filesystem.h" />
+ <ClInclude Include="src\fixedPoint_math.h" />
<ClInclude Include="src\icon.h" />
+ <ClInclude Include="src\network.h" />
<ClInclude Include="src\platform.h" />
- <ClInclude Include="src\pragmas.h" />
+ <ClInclude Include="src\tiles.h" />
<ClInclude Include="src\win32_compat.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
--- a/Engine/Engine.vcxproj.filters
+++ b/Engine/Engine.vcxproj.filters
@@ -23,9 +23,6 @@
<ClCompile Include="src\mmulti_stable.cpp">
<Filter>Source Files</Filter>
</ClCompile>
- <ClCompile Include="src\pragmas.c">
- <Filter>Source Files</Filter>
- </ClCompile>
<ClCompile Include="src\enet\host.c">
<Filter>enet</Filter>
</ClCompile>
@@ -62,6 +59,15 @@
<ClCompile Include="src\filesystem.c">
<Filter>Source Files</Filter>
</ClCompile>
+ <ClCompile Include="src\network.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="src\tiles.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
+ <ClCompile Include="src\fixedPoint_math.c">
+ <Filter>Source Files</Filter>
+ </ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\build.h">
@@ -79,9 +85,6 @@
<ClInclude Include="src\platform.h">
<Filter>Header Files</Filter>
</ClInclude>
- <ClInclude Include="src\pragmas.h">
- <Filter>Header Files</Filter>
- </ClInclude>
<ClInclude Include="src\win32_compat.h">
<Filter>Header Files</Filter>
</ClInclude>
@@ -92,6 +95,15 @@
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\filesystem.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="src\network.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="src\tiles.h">
+ <Filter>Header Files</Filter>
+ </ClInclude>
+ <ClInclude Include="src\fixedPoint_math.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
--- a/Engine/src/display.c
+++ b/Engine/src/display.c
@@ -1246,8 +1246,8 @@
uint8_t* transPointer = transluc;
uint8_t* bufferPointer = buffer;
int i;
+ FILE* file;
-
for (i=0; i < 65535; i++) {
bufferPointer[0] = (lastPalette[(*transPointer)*3+0]) / 63.0 * 255;
@@ -1265,7 +1265,7 @@
- FILE* file = fopen("transluc.tga", "w");
+ file = fopen("transluc.tga", "w");
memset(tga_header, 0, 18);
tga_header[2] = 2;
--- a/Engine/src/engine.c
+++ b/Engine/src/engine.c
@@ -106,8 +106,8 @@
-enum vector_index_e {VEC_X=0,VECY=1};
-enum screenSpaceCoo_index_e {VEC_COL_X=0,VEC_DIST=1};
+enum vector_index_e {VEC_X=0,VEC_Y=1};
+enum screenSpaceCoo_index_e {VEC_COL=0,VEC_DIST=1};
typedef int32_t vector_t[2];
typedef int32_t coo2D_t[2];
// This is the structure emitted for each wall that is potentially visible.
@@ -122,34 +122,22 @@
// Potentially Visible walls are stored in this stack.
pvWall_t pvWalls[MAXWALLSB];
-/*
-//This is the structure emitted for each bunch detected during scanning.
-typedef struct bunch_s{
- short firstWallId;
- short lastWallId;
-} bunch_t;
-//Stack containing the bunchs.
-bunch_t bunchList[MAXWALLSB];
-*/
-
-
-
-
-
-
-
//xb1 and xb2 seems to be storing the column of the wall endpoint
//yb1 and yb2 store the Y distance from the camera.
-static int32_t xb1[MAXWALLSB], yb1[MAXWALLSB], xb2[MAXWALLSB], yb2[MAXWALLSB];
+//static int32_t xb1[MAXWALLSB], yb1[MAXWALLSB], xb2[MAXWALLSB], yb2[MAXWALLSB];
+
+/*
//rx1,rx2,ry1,ry2 stores the cameraspace wall endpoints coordinates.
static int32_t rx1[MAXWALLSB], ry1[MAXWALLSB], rx2[MAXWALLSB], ry2[MAXWALLSB];
+static short thesector[MAXWALLSB], thewall[MAXWALLSB];
+*/
-//
-static short p2[MAXWALLSB], thesector[MAXWALLSB], thewall[MAXWALLSB];
+// bunchWallsList contains the list of walls in a bunch.
+static short bunchWallsList[MAXWALLSB];
static short bunchfirst[MAXWALLSB], bunchlast[MAXWALLSB];
@@ -463,14 +451,14 @@
goto skipitaddwall;
//Project the point onto screen and see in which column it belongs.
- xb1[numscans] = halfxdimen + scale(xp1,halfxdimen,yp1);
+ pvWalls[numscans].screenSpaceCoo[0][VEC_COL] = halfxdimen + scale(xp1,halfxdimen,yp1);
if (xp1 >= 0)
- xb1[numscans]++; /* Fix for SIGNED divide */
+ pvWalls[numscans].screenSpaceCoo[0][VEC_COL]++; /* Fix for SIGNED divide */
- if (xb1[numscans] >= xdimen)
- xb1[numscans] = xdimen-1;
+ if (pvWalls[numscans].screenSpaceCoo[0][VEC_COL] >= xdimen)
+ pvWalls[numscans].screenSpaceCoo[0][VEC_COL] = xdimen-1;
- yb1[numscans] = yp1;
+ pvWalls[numscans].screenSpaceCoo[0][VEC_DIST] = yp1;
}
else{
@@ -477,48 +465,49 @@
if (xp2 < -yp2)
goto skipitaddwall;
- xb1[numscans] = 0;
+ pvWalls[numscans].screenSpaceCoo[0][VEC_COL] = 0;
tempint = yp1-yp2+xp1-xp2;
if (tempint == 0)
goto skipitaddwall;
- yb1[numscans] = yp1 + scale(yp2-yp1,xp1+yp1,tempint);
+ pvWalls[numscans].screenSpaceCoo[0][VEC_DIST] = yp1 + scale(yp2-yp1,xp1+yp1,tempint);
}
- if (yb1[numscans] < 256)
+ if (pvWalls[numscans].screenSpaceCoo[0][VEC_DIST] < 256)
goto skipitaddwall;
if (xp2 <= yp2){
if ((xp2 < -yp2) || (yp2 == 0)) goto skipitaddwall;
- xb2[numscans] = halfxdimen + scale(xp2,halfxdimen,yp2) - 1;
- if (xp2 >= 0) xb2[numscans]++; /* Fix for SIGNED divide */
- if (xb2[numscans] >= xdimen) xb2[numscans] = xdimen-1;
- yb2[numscans] = yp2;
+ pvWalls[numscans].screenSpaceCoo[1][VEC_COL] = halfxdimen + scale(xp2,halfxdimen,yp2) - 1;
+ if (xp2 >= 0) pvWalls[numscans].screenSpaceCoo[1][VEC_COL]++; /* Fix for SIGNED divide */
+ if (pvWalls[numscans].screenSpaceCoo[1][VEC_COL] >= xdimen) pvWalls[numscans].screenSpaceCoo[1][VEC_COL] = xdimen-1;
+ pvWalls[numscans].screenSpaceCoo[1][VEC_DIST] = yp2;
}
else{
if (xp1 > yp1) goto skipitaddwall;
- xb2[numscans] = xdimen-1;
+ pvWalls[numscans].screenSpaceCoo[1][VEC_COL] = xdimen-1;
tempint = xp2-xp1+yp1-yp2;
if (tempint == 0) goto skipitaddwall;
- yb2[numscans] = yp1 + scale(yp2-yp1,yp1-xp1,tempint);
+ pvWalls[numscans].screenSpaceCoo[1][VEC_DIST] = yp1 + scale(yp2-yp1,yp1-xp1,tempint);
}
- if ((yb2[numscans] < 256) || (xb1[numscans] > xb2[numscans])) goto skipitaddwall;
+ if ((pvWalls[numscans].screenSpaceCoo[1][VEC_DIST] < 256) || (pvWalls[numscans].screenSpaceCoo[0][VEC_COL] > pvWalls[numscans].screenSpaceCoo[1][VEC_COL])) goto skipitaddwall;
// Made it all the way!
// Time to add this wall information to the stack of wall potentially visible.
- thesector[numscans] = sectnum;
- thewall[numscans] = z;
+ pvWalls[numscans].sectorId = sectnum;
+ pvWalls[numscans].worldWallId = z;
//Save the camera space wall endpoints coordinate (camera origin at player location + rotated according to player orientation).
- rx1[numscans] = xp1;
- ry1[numscans] = yp1;
- rx2[numscans] = xp2;
- ry2[numscans] = yp2;
+ pvWalls[numscans].cameraSpaceCoo[0][VEC_X] = xp1;
+ pvWalls[numscans].cameraSpaceCoo[0][VEC_Y] = yp1;
+ pvWalls[numscans].cameraSpaceCoo[1][VEC_X] = xp2;
+ pvWalls[numscans].cameraSpaceCoo[1][VEC_Y] = yp2;
+
- p2[numscans] = numscans+1;
+ bunchWallsList[numscans] = numscans+1;
numscans++;
skipitaddwall:
@@ -525,24 +514,26 @@
if ((wall[z].point2 < z) && (scanfirst < numscans))
{
- p2[numscans-1] = scanfirst;
+ bunchWallsList[numscans-1] = scanfirst;
scanfirst = numscans;
}
}
//FCS: TODO rename this p2[] to bunchList[] or something like that. This name is an abomination
+ // DONE, p2 is now called "bunchWallsList".
//Break down the list of walls for this sector into bunchs. Since a bunch is a
// continuously visible list of wall: A sector can generate many bunches.
for(z=numscansbefore; z<numscans; z++)
{
- if ((wall[thewall[z]].point2 != thewall[p2[z]]) || (xb2[z] >= xb1[p2[z]]))
+ if ((wall[pvWalls[z].worldWallId].point2 !=
+ pvWalls[bunchWallsList[z]].worldWallId) || (pvWalls[z].screenSpaceCoo[1][VEC_COL] >= pvWalls[bunchWallsList[z]].screenSpaceCoo[0][VEC_COL]))
{
// Create an entry in the bunch list
- bunchfirst[numbunches++] = p2[z];
+ bunchfirst[numbunches++] = bunchWallsList[z];
//Mark the end of the bunch wall list.
- p2[z] = -1;
+ bunchWallsList[z] = -1;
}
}
@@ -549,7 +540,7 @@
//For each bunch, find the last wall and cache it in bunchlast.
for(z=bunchfrst; z<numbunches; z++)
{
- for(zz=bunchfirst[z]; p2[zz]>=0; zz=p2[zz]);
+ for(zz=bunchfirst[z]; bunchWallsList[zz]>=0; zz=bunchWallsList[zz]);
bunchlast[z] = zz;
}
@@ -568,23 +559,25 @@
static void prepwall(int32_t z, walltype *wal)
{
int32_t i, l=0, ol=0, splc, sinc, x, topinc, top, botinc, bot, walxrepeat;
-
+ vector_t* wallCoo = pvWalls[z].cameraSpaceCoo;
+
walxrepeat = (wal->xrepeat<<3);
/* lwall calculation */
- i = xb1[z]-halfxdimen;
+ i = pvWalls[z].screenSpaceCoo[0][VEC_COL]-halfxdimen;
- topinc = -(ry1[z]>>2);
- botinc = ((ry2[z]-ry1[z])>>8);
+ //Let's use some of the camera space wall coordinate now.
+ topinc = -(wallCoo[0][VEC_Y]>>2);
+ botinc = ((wallCoo[1][VEC_Y]-wallCoo[0][VEC_Y])>>8);
- top = mulscale5(rx1[z],xdimen)+mulscale2(topinc,i);
- bot = mulscale11(rx1[z]-rx2[z],xdimen)+mulscale2(botinc,i);
+ top = mulscale5(wallCoo[0][VEC_X],xdimen)+mulscale2(topinc,i);
+ bot = mulscale11(wallCoo[0][VEC_X]-wallCoo[1][VEC_X],xdimen)+mulscale2(botinc,i);
- splc = mulscale19(ry1[z],xdimscale);
- sinc = mulscale16(ry2[z]-ry1[z],xdimscale);
+ splc = mulscale19(wallCoo[0][VEC_Y],xdimscale);
+ sinc = mulscale16(wallCoo[1][VEC_Y]-wallCoo[0][VEC_Y],xdimscale);
//X screenspce column of point Z.
- x = xb1[z];
+ x = pvWalls[z].screenSpaceCoo[0][VEC_COL];
if (bot != 0)
{
@@ -595,7 +588,7 @@
}
//If the wall is less than 4 column wide.
- while (x+4 <= xb2[z])
+ while (x+4 <= pvWalls[z].screenSpaceCoo[1][VEC_COL])
{
top += topinc;
bot += botinc;
@@ -618,7 +611,7 @@
}
//If the wall is less than 2 columns wide.
- if (x+2 <= xb2[z])
+ if (x+2 <= pvWalls[z].screenSpaceCoo[1][VEC_COL])
{
top += (topinc>>1);
bot += (botinc>>1);
@@ -636,7 +629,7 @@
}
//The wall is 1 column wide.
- if (x+1 <= xb2[z])
+ if (x+1 <= pvWalls[z].screenSpaceCoo[1][VEC_COL])
{
bot += (botinc>>2);
if (bot != 0)
@@ -647,16 +640,16 @@
}
}
- if (lwall[xb1[z]] < 0)
- lwall[xb1[z]] = 0;
+ if (lwall[pvWalls[z].screenSpaceCoo[0][VEC_COL]] < 0)
+ lwall[pvWalls[z].screenSpaceCoo[0][VEC_COL]] = 0;
- if ((lwall[xb2[z]] >= walxrepeat) && (walxrepeat))
- lwall[xb2[z]] = walxrepeat-1;
+ if ((lwall[pvWalls[z].screenSpaceCoo[1][VEC_COL]] >= walxrepeat) && (walxrepeat))
+ lwall[pvWalls[z].screenSpaceCoo[1][VEC_COL]] = walxrepeat-1;
if (wal->cstat&8)
{
walxrepeat--;
- for(x=xb1[z]; x<=xb2[z]; x++)
+ for(x=pvWalls[z].screenSpaceCoo[0][VEC_COL]; x<=pvWalls[z].screenSpaceCoo[1][VEC_COL]; x++)
lwall[x] = walxrepeat-lwall[x];
}
}
@@ -1583,7 +1576,7 @@
int32_t j, k, l, m, n, x, z, wallnum, nextsectnum, globalhorizbak;
short *topptr, *botptr;
- sectnum = thesector[bunchfirst[bunch]];
+ sectnum = pvWalls[bunchfirst[bunch]].sectorId;
sec = §or[sectnum];
globalhorizbak = globalhoriz;
@@ -1631,9 +1624,9 @@
k = 11 - (picsiz[globalpicnum]&15) - pskybits;
x = -1;
- for(z=bunchfirst[bunch]; z>=0; z=p2[z])
+ for(z=bunchfirst[bunch]; z>=0; z=bunchWallsList[z])
{
- wallnum = thewall[z];
+ wallnum = pvWalls[z].worldWallId;
nextsectnum = wall[wallnum].nextsector;
if (dastat == 0) j = sector[nextsectnum].ceilingstat;
@@ -1641,27 +1634,27 @@
if ((nextsectnum < 0) || (wall[wallnum].cstat&32) || ((j&1) == 0))
{
- if (x == -1) x = xb1[z];
+ if (x == -1) x = pvWalls[z].screenSpaceCoo[0][VEC_COL];
if (parallaxtype == 0)
{
n = mulscale16(xdimenrecip,viewingrange);
- for(j=xb1[z]; j<=xb2[z]; j++)
+ for(j=pvWalls[z].screenSpaceCoo[0][VEC_COL]; j<=pvWalls[z].screenSpaceCoo[1][VEC_COL]; j++)
lplc[j] = (((mulscale23(j-halfxdimen,n)+globalang)&2047)>>k);
}
else
{
- for(j=xb1[z]; j<=xb2[z]; j++)
+ for(j=pvWalls[z].screenSpaceCoo[0][VEC_COL]; j<=pvWalls[z].screenSpaceCoo[1][VEC_COL]; j++)
lplc[j] = ((((int32_t)radarang2[j]+globalang)&2047)>>k);
}
if (parallaxtype == 2)
{
n = mulscale16(xdimscale,viewingrange);
- for(j=xb1[z]; j<=xb2[z]; j++)
+ for(j=pvWalls[z].screenSpaceCoo[0][VEC_COL]; j<=pvWalls[z].screenSpaceCoo[1][VEC_COL]; j++)
swplc[j] = mulscale14(sintable[((int32_t)radarang2[j]+512)&2047],n);
}
else
- clearbuf(&swplc[xb1[z]],xb2[z]-xb1[z]+1,mulscale16(xdimscale,viewingrange));
+ clearbuf(&swplc[pvWalls[z].screenSpaceCoo[0][VEC_COL]],pvWalls[z].screenSpaceCoo[1][VEC_COL]-pvWalls[z].screenSpaceCoo[0][VEC_COL]+1,mulscale16(xdimscale,viewingrange));
}
else if (x >= 0)
{
@@ -1669,12 +1662,12 @@
m = (picsiz[globalpicnum]&15);
globalpicnum = l+pskyoff[lplc[x]>>m];
- if (((lplc[x]^lplc[xb1[z]-1])>>m) == 0)
- wallscan(x,xb1[z]-1,topptr,botptr,swplc,lplc);
+ if (((lplc[x]^lplc[pvWalls[z].screenSpaceCoo[0][VEC_COL]-1])>>m) == 0)
+ wallscan(x,pvWalls[z].screenSpaceCoo[0][VEC_COL]-1,topptr,botptr,swplc,lplc);
else
{
j = x;
- while (x < xb1[z])
+ while (x < pvWalls[z].screenSpaceCoo[0][VEC_COL])
{
n = l+pskyoff[lplc[x]>>m];
if (n != globalpicnum)
@@ -1700,12 +1693,12 @@
m = (picsiz[globalpicnum]&15);
globalpicnum = l+pskyoff[lplc[x]>>m];
- if (((lplc[x]^lplc[xb2[bunchlast[bunch]]])>>m) == 0)
- wallscan(x,xb2[bunchlast[bunch]],topptr,botptr,swplc,lplc);
+ if (((lplc[x]^lplc[pvWalls[bunchlast[bunch]].screenSpaceCoo[1][VEC_COL]])>>m) == 0)
+ wallscan(x,pvWalls[bunchlast[bunch]].screenSpaceCoo[1][VEC_COL],topptr,botptr,swplc,lplc);
else
{
j = x;
- while (x <= xb2[bunchlast[bunch]])
+ while (x <= pvWalls[bunchlast[bunch]].screenSpaceCoo[1][VEC_COL])
{
n = l+pskyoff[lplc[x]>>m];
if (n != globalpicnum)
@@ -1933,16 +1926,16 @@
int32_t s1, s2, s3, s4, ix1, ix2, iy1, iy2, t;
z <<= 7;
- s1 = mulscale20(globaluclip,yb1[w]);
- s2 = mulscale20(globaluclip,yb2[w]);
- s3 = mulscale20(globaldclip,yb1[w]);
- s4 = mulscale20(globaldclip,yb2[w]);
+ s1 = mulscale20(globaluclip,pvWalls[w].screenSpaceCoo[0][VEC_DIST]);
+ s2 = mulscale20(globaluclip,pvWalls[w].screenSpaceCoo[1][VEC_DIST]);
+ s3 = mulscale20(globaldclip,pvWalls[w].screenSpaceCoo[0][VEC_DIST]);
+ s4 = mulscale20(globaldclip,pvWalls[w].screenSpaceCoo[1][VEC_DIST]);
bad = (z<s1)+((z<s2)<<1)+((z>s3)<<2)+((z>s4)<<3);
- ix1 = xb1[w];
- iy1 = yb1[w];
- ix2 = xb2[w];
- iy2 = yb2[w];
+ ix1 = pvWalls[w].screenSpaceCoo[0][VEC_COL];
+ iy1 = pvWalls[w].screenSpaceCoo[0][VEC_DIST];
+ ix2 = pvWalls[w].screenSpaceCoo[1][VEC_COL];
+ iy2 = pvWalls[w].screenSpaceCoo[1][VEC_DIST];
if ((bad&3) == 3)
{
@@ -1959,24 +1952,24 @@
if (bad&3)
{
t = divscale30(z-s1,s2-s1);
- inty = yb1[w] + mulscale30(yb2[w]-yb1[w],t);
- xcross = xb1[w] + scale(mulscale30(yb2[w],t),xb2[w]-xb1[w],inty);
+ inty = pvWalls[w].screenSpaceCoo[0][VEC_DIST] + mulscale30(pvWalls[w].screenSpaceCoo[1][VEC_DIST]-pvWalls[w].screenSpaceCoo[0][VEC_DIST],t);
+ xcross = pvWalls[w].screenSpaceCoo[0][VEC_COL] + scale(mulscale30(pvWalls[w].screenSpaceCoo[1][VEC_DIST],t),pvWalls[w].screenSpaceCoo[1][VEC_COL]-pvWalls[w].screenSpaceCoo[0][VEC_COL],inty);
if ((bad&3) == 2)
{
- if (xb1[w] <= xcross) {
+ if (pvWalls[w].screenSpaceCoo[0][VEC_COL] <= xcross) {
iy2 = inty;
ix2 = xcross;
}
- clearbufbyte(&mostbuf[xcross+1],(xb2[w]-xcross)*sizeof(mostbuf[0]),0L);
+ clearbufbyte(&mostbuf[xcross+1],(pvWalls[w].screenSpaceCoo[1][VEC_COL]-xcross)*sizeof(mostbuf[0]),0L);
}
else
{
- if (xcross <= xb2[w]) {
+ if (xcross <= pvWalls[w].screenSpaceCoo[1][VEC_COL]) {
iy1 = inty;
ix1 = xcross;
}
- clearbufbyte(&mostbuf[xb1[w]],(xcross-xb1[w]+1)*sizeof(mostbuf[0]),0L);
+ clearbufbyte(&mostbuf[pvWalls[w].screenSpaceCoo[0][VEC_COL]],(xcross-pvWalls[w].screenSpaceCoo[0][VEC_COL]+1)*sizeof(mostbuf[0]),0L);
}
}
@@ -1983,24 +1976,24 @@
if (bad&12)
{
t = divscale30(z-s3,s4-s3);
- inty = yb1[w] + mulscale30(yb2[w]-yb1[w],t);
- xcross = xb1[w] + scale(mulscale30(yb2[w],t),xb2[w]-xb1[w],inty);
+ inty = pvWalls[w].screenSpaceCoo[0][VEC_DIST] + mulscale30(pvWalls[w].screenSpaceCoo[1][VEC_DIST]-pvWalls[w].screenSpaceCoo[0][VEC_DIST],t);
+ xcross = pvWalls[w].screenSpaceCoo[0][VEC_COL] + scale(mulscale30(pvWalls[w].screenSpaceCoo[1][VEC_DIST],t),pvWalls[w].screenSpaceCoo[1][VEC_COL]-pvWalls[w].screenSpaceCoo[0][VEC_COL],inty);
if ((bad&12) == 8)
{
- if (xb1[w] <= xcross) {
+ if (pvWalls[w].screenSpaceCoo[0][VEC_COL] <= xcross) {
iy2 = inty;
ix2 = xcross;
}
- clearbufbyte(&mostbuf[xcross+1],(xb2[w]-xcross)*sizeof(mostbuf[0]),ydimen+(ydimen<<16));
+ clearbufbyte(&mostbuf[xcross+1],(pvWalls[w].screenSpaceCoo[1][VEC_COL]-xcross)*sizeof(mostbuf[0]),ydimen+(ydimen<<16));
}
else
{
- if (xcross <= xb2[w]) {
+ if (xcross <= pvWalls[w].screenSpaceCoo[1][VEC_COL]) {
iy1 = inty;
ix1 = xcross;
}
- clearbufbyte(&mostbuf[xb1[w]],(xcross-xb1[w]+1)*sizeof(mostbuf[0]),ydimen+(ydimen<<16));
+ clearbufbyte(&mostbuf[pvWalls[w].screenSpaceCoo[0][VEC_COL]],(xcross-pvWalls[w].screenSpaceCoo[0][VEC_COL]+1)*sizeof(mostbuf[0]),ydimen+(ydimen<<16));
}
}
@@ -2034,7 +2027,7 @@
return(owallmost(mostbuf,w,z));
}
- i = thewall[w];
+ i = pvWalls[w].worldWallId;
if (i == sector[sectnum].wallptr)
return(owallmost(mostbuf,w,z));
@@ -2049,7 +2042,7 @@
dy = wall[i].y-wall[fw].y;
dasqr = krecipasm(nsqrtasm(dx*dx+dy*dy));
- if (xb1[w] == 0){
+ if (pvWalls[w].screenSpaceCoo[0][VEC_COL] == 0){
xv = cosglobalang+sinviewingrangeglobalang;
yv = singlobalang-cosviewingrangeglobalang;
}
@@ -2075,7 +2068,7 @@
z1 = dmulscale24(dx*t,mulscale20(y2,i)+((y1-wall[fw].y)<<8),-dy*t,mulscale20(x2,i)+((x1-wall[fw].x)<<8))+((z1-globalposz)<<7);
- if (xb2[w] == xdimen-1){
+ if (pvWalls[w].screenSpaceCoo[1][VEC_COL] == xdimen-1){
xv = cosglobalang-sinviewingrangeglobalang;
yv = singlobalang+cosviewingrangeglobalang;
}
@@ -2102,16 +2095,16 @@
z2 = dmulscale24(dx*t,mulscale20(y2,i)+((y1-wall[fw].y)<<8),-dy*t,mulscale20(x2,i)+((x1-wall[fw].x)<<8))+((z2-globalposz)<<7);
- s1 = mulscale20(globaluclip,yb1[w]);
- s2 = mulscale20(globaluclip,yb2[w]);
- s3 = mulscale20(globaldclip,yb1[w]);
- s4 = mulscale20(globaldclip,yb2[w]);
+ s1 = mulscale20(globaluclip,pvWalls[w].screenSpaceCoo[0][VEC_DIST]);
+ s2 = mulscale20(globaluclip,pvWalls[w].screenSpaceCoo[1][VEC_DIST]);
+ s3 = mulscale20(globaldclip,pvWalls[w].screenSpaceCoo[0][VEC_DIST]);
+ s4 = mulscale20(globaldclip,pvWalls[w].screenSpaceCoo[1][VEC_DIST]);
bad = (z1<s1)+((z2<s2)<<1)+((z1>s3)<<2)+((z2>s4)<<3);
- ix1 = xb1[w];
- ix2 = xb2[w];
- iy1 = yb1[w];
- iy2 = yb2[w];
+ ix1 = pvWalls[w].screenSpaceCoo[0][VEC_COL];
+ ix2 = pvWalls[w].screenSpaceCoo[1][VEC_COL];
+ iy1 = pvWalls[w].screenSpaceCoo[0][VEC_DIST];
+ iy2 = pvWalls[w].screenSpaceCoo[1][VEC_DIST];
oz1 = z1;
oz2 = z2;
@@ -2128,25 +2121,25 @@
if (bad&3){
/* inty = intz / (globaluclip>>16) */
t = divscale30(oz1-s1,s2-s1+oz1-oz2);
- inty = yb1[w] + mulscale30(yb2[w]-yb1[w],t);
+ inty = pvWalls[w].screenSpaceCoo[0][VEC_DIST] + mulscale30(pvWalls[w].screenSpaceCoo[1][VEC_DIST]-pvWalls[w].screenSpaceCoo[0][VEC_DIST],t);
intz = oz1 + mulscale30(oz2-oz1,t);
- xcross = xb1[w] + scale(mulscale30(yb2[w],t),xb2[w]-xb1[w],inty);
+ xcross = pvWalls[w].screenSpaceCoo[0][VEC_COL] + scale(mulscale30(pvWalls[w].screenSpaceCoo[1][VEC_DIST],t),pvWalls[w].screenSpaceCoo[1][VEC_COL]-pvWalls[w].screenSpaceCoo[0][VEC_COL],inty);
if ((bad&3) == 2){
- if (xb1[w] <= xcross){
+ if (pvWalls[w].screenSpaceCoo[0][VEC_COL] <= xcross){
z2 = intz;
iy2 = inty;
ix2 = xcross;
}
- clearbufbyte(&mostbuf[xcross+1],(xb2[w]-xcross)*sizeof(mostbuf[0]),0L);
+ clearbufbyte(&mostbuf[xcross+1],(pvWalls[w].screenSpaceCoo[1][VEC_COL]-xcross)*sizeof(mostbuf[0]),0L);
}
else{
- if (xcross <= xb2[w]) {
+ if (xcross <= pvWalls[w].screenSpaceCoo[1][VEC_COL]) {
z1 = intz;
iy1 = inty;
ix1 = xcross;
}
- clearbufbyte(&mostbuf[xb1[w]],(xcross-xb1[w]+1)*sizeof(mostbuf[0]),0L);
+ clearbufbyte(&mostbuf[pvWalls[w].screenSpaceCoo[0][VEC_COL]],(xcross-pvWalls[w].screenSpaceCoo[0][VEC_COL]+1)*sizeof(mostbuf[0]),0L);
}
}
@@ -2153,25 +2146,25 @@
if (bad&12){
/* inty = intz / (globaldclip>>16) */
t = divscale30(oz1-s3,s4-s3+oz1-oz2);
- inty = yb1[w] + mulscale30(yb2[w]-yb1[w],t);
+ inty = pvWalls[w].screenSpaceCoo[0][VEC_DIST] + mulscale30(pvWalls[w].screenSpaceCoo[1][VEC_DIST]-pvWalls[w].screenSpaceCoo[0][VEC_DIST],t);
intz = oz1 + mulscale30(oz2-oz1,t);
- xcross = xb1[w] + scale(mulscale30(yb2[w],t),xb2[w]-xb1[w],inty);
+ xcross = pvWalls[w].screenSpaceCoo[0][VEC_COL] + scale(mulscale30(pvWalls[w].screenSpaceCoo[1][VEC_DIST],t),pvWalls[w].screenSpaceCoo[1][VEC_COL]-pvWalls[w].screenSpaceCoo[0][VEC_COL],inty);
if ((bad&12) == 8){
- if (xb1[w] <= xcross) {
+ if (pvWalls[w].screenSpaceCoo[0][VEC_COL] <= xcross) {
z2 = intz;
iy2 = inty;
ix2 = xcross;
}
- clearbufbyte(&mostbuf[xcross+1],(xb2[w]-xcross)*sizeof(mostbuf[0]),ydimen+(ydimen<<16));
+ clearbufbyte(&mostbuf[xcross+1],(pvWalls[w].screenSpaceCoo[1][VEC_COL]-xcross)*sizeof(mostbuf[0]),ydimen+(ydimen<<16));
}
else{
- if (xcross <= xb2[w]) {
+ if (xcross <= pvWalls[w].screenSpaceCoo[1][VEC_COL]) {
z1 = intz;
iy1 = inty;
ix1 = xcross;
}
- clearbufbyte(&mostbuf[xb1[w]],(xcross-xb1[w]+1)*sizeof(mostbuf[0]),ydimen+(ydimen<<16));
+ clearbufbyte(&mostbuf[pvWalls[w].screenSpaceCoo[0][VEC_COL]],(xcross-pvWalls[w].screenSpaceCoo[0][VEC_COL]+1)*sizeof(mostbuf[0]),ydimen+(ydimen<<16));
}
}
@@ -2202,12 +2195,12 @@
uint8_t andwstat1, andwstat2;
z = bunchfirst[bunch];
- sectnum = thesector[z];
+ sectnum = pvWalls[z].sectorId;
sec = §or[sectnum];
andwstat1 = 0xff;
andwstat2 = 0xff;
- for(; z>=0; z=p2[z]){ /* uplc/dplc calculation */
+ for(; z>=0; z=bunchWallsList[z]){ /* uplc/dplc calculation */
andwstat1 &= wallmost(uplc,z,sectnum,(uint8_t )0);
andwstat2 &= wallmost(dplc,z,sectnum,(uint8_t )1);
@@ -2216,28 +2209,28 @@
/* draw ceilings */
if ((andwstat1&3) != 3){
if ((sec->ceilingstat&3) == 2)
- grouscan(xb1[bunchfirst[bunch]],xb2[bunchlast[bunch]],sectnum,0);
+ grouscan(pvWalls[bunchfirst[bunch]].screenSpaceCoo[0][VEC_COL],pvWalls[bunchlast[bunch]].screenSpaceCoo[1][VEC_COL],sectnum,0);
else if ((sec->ceilingstat&1) == 0)
- ceilscan(xb1[bunchfirst[bunch]],xb2[bunchlast[bunch]],sectnum);
+ ceilscan(pvWalls[bunchfirst[bunch]].screenSpaceCoo[0][VEC_COL],pvWalls[bunchlast[bunch]].screenSpaceCoo[1][VEC_COL],sectnum);
else
- parascan(xb1[bunchfirst[bunch]],xb2[bunchlast[bunch]],sectnum,0,bunch);
+ parascan(pvWalls[bunchfirst[bunch]].screenSpaceCoo[0][VEC_COL],pvWalls[bunchlast[bunch]].screenSpaceCoo[1][VEC_COL],sectnum,0,bunch);
}
/* draw floors */
if ((andwstat2&12) != 12){
if ((sec->floorstat&3) == 2)
- grouscan(xb1[bunchfirst[bunch]],xb2[bunchlast[bunch]],sectnum,1);
+ grouscan(pvWalls[bunchfirst[bunch]].screenSpaceCoo[0][VEC_COL],pvWalls[bunchlast[bunch]].screenSpaceCoo[1][VEC_COL],sectnum,1);
else if ((sec->floorstat&1) == 0)
- florscan(xb1[bunchfirst[bunch]],xb2[bunchlast[bunch]],sectnum);
+ florscan(pvWalls[bunchfirst[bunch]].screenSpaceCoo[0][VEC_COL],pvWalls[bunchlast[bunch]].screenSpaceCoo[1][VEC_COL],sectnum);
else
- parascan(xb1[bunchfirst[bunch]],xb2[bunchlast[bunch]],sectnum,1,bunch);
+ parascan(pvWalls[bunchfirst[bunch]].screenSpaceCoo[0][VEC_COL],pvWalls[bunchlast[bunch]].screenSpaceCoo[1][VEC_COL],sectnum,1,bunch);
}
/* DRAW WALLS SECTION! */
- for(z=bunchfirst[bunch]; z>=0; z=p2[z]){
+ for(z=bunchfirst[bunch]; z>=0; z=bunchWallsList[z]){
- x1 = xb1[z];
- x2 = xb2[z];
+ x1 = pvWalls[z].screenSpaceCoo[0][VEC_COL];
+ x2 = pvWalls[z].screenSpaceCoo[1][VEC_COL];
if (umost[x2] >= dmost[x2])
{
@@ -2254,7 +2247,7 @@
}
}
- wallnum = thewall[z];
+ wallnum = pvWalls[z].worldWallId;
wal = &wall[wallnum];
nextsectnum = wal->nextsector;
nextsec = §or[nextsectnum];
@@ -2414,7 +2407,7 @@
globalshade = (int32_t)wal->shade;
globalpal = (int32_t)wal->pal;
- wallnum = thewall[z];
+ wallnum = pvWalls[z].worldWallId;
wal = &wall[wallnum];
}
else{
@@ -2649,13 +2642,13 @@
int32_t x11, y11, x21, y21, x12, y12, x22, y22, dx, dy, t1, t2;
//It seems we are going to work in Worldspace coordinates.
- wal = &wall[thewall[pvWallID1]];
+ wal = &wall[pvWalls[pvWallID1].worldWallId];
x11 = wal->x;
y11 = wal->y;
wal = &wall[wal->point2];
x21 = wal->x;
y21 = wal->y;
- wal = &wall[thewall[pvWallID2]];
+ wal = &wall[pvWalls[pvWallID2].worldWallId];
x12 = wal->x;
y12 = wal->y;
wal = &wall[wal->point2];
@@ -2737,8 +2730,8 @@
int32_t x1b1, x2b1, x1b2, x2b2;
- x1b1 = xb1[bunchfirst[firstBunchID]];
- x2b2 = xb2[bunchlast[secondBunchID]]+1;
+ x1b1 = pvWalls[bunchfirst[firstBunchID]].screenSpaceCoo[0][VEC_COL];
+ x2b2 = pvWalls[bunchlast[secondBunchID]].screenSpaceCoo[1][VEC_COL]+1;
if (x1b1 >= x2b2)
{
//Bunch 1 left side is completely on the right of bunch2's right in screenspace: They do not overlap.
@@ -2746,8 +2739,8 @@
}
- x1b2 = xb1[bunchfirst[secondBunchID]];
- x2b1 = xb2[bunchlast[firstBunchID]]+1;
+ x1b2 = pvWalls[bunchfirst[secondBunchID]].screenSpaceCoo[0][VEC_COL];
+ x2b1 = pvWalls[bunchlast[firstBunchID]].screenSpaceCoo[1][VEC_COL]+1;
if (x1b2 >= x2b1)
{
//Bunch 2 left side is completely on the right of bunch 1 right side: They do not overlap.
@@ -2760,8 +2753,8 @@
//Get the last wall in the bunch2.
int lastWallID;
for(lastWallID=bunchfirst[secondBunchID];
- xb2[lastWallID]<x1b1;
- lastWallID=p2[lastWallID]);
+ pvWalls[lastWallID].screenSpaceCoo[1][VEC_COL]<x1b1;
+ lastWallID=bunchWallsList[lastWallID]);
return(wallfront(bunchfirst[firstBunchID],lastWallID));
}
@@ -2770,8 +2763,8 @@
//Get the last wall in the bunch.
int lastWallID;
for(lastWallID=bunchfirst[firstBunchID];
- xb2[lastWallID]<x1b2;
- lastWallID=p2[lastWallID]);
+ pvWalls[lastWallID].screenSpaceCoo[1][VEC_COL]<x1b2;
+ lastWallID=bunchWallsList[lastWallID]);
return(wallfront(lastWallID,bunchfirst[secondBunchID]));
}
@@ -2944,9 +2937,9 @@
mirrorsx2 = 0;
for(i=numscans-1; i>=0; i--)
{
- if (wall[thewall[i]].nextsector < 0) continue;
- if (xb1[i] < mirrorsx1) mirrorsx1 = xb1[i];
- if (xb2[i] > mirrorsx2) mirrorsx2 = xb2[i];
+ if (wall[pvWalls[i].worldWallId].nextsector < 0) continue;
+ if (pvWalls[i].screenSpaceCoo[0][VEC_COL] < mirrorsx1) mirrorsx1 = pvWalls[i].screenSpaceCoo[0][VEC_COL];
+ if (pvWalls[i].screenSpaceCoo[1][VEC_COL] > mirrorsx2) mirrorsx2 = pvWalls[i].screenSpaceCoo[1][VEC_COL];
}
if (stereomode)
@@ -3022,8 +3015,9 @@
if (automapping)
{
- for(z=bunchfirst[closest]; z>=0; z=p2[z])
- show2dwall[thewall[z]>>3] |= pow2char[thewall[z]&7];
+ for(z=bunchfirst[closest]; z>=0; z=bunchWallsList[z])
+ show2dwall[pvWalls[z].worldWallId>>3] |=
+ pow2char [pvWalls[z].worldWallId&7];
}
//Since we just rendered a bunch, lower the current stack element so we can treat the next item
@@ -3684,33 +3678,54 @@
/* Assume npoints=4 with polygon on &rx1,&ry1 */
+//FCS This is horrible to read: I hate you.
static int clippoly4(int32_t cx1, int32_t cy1, int32_t cx2, int32_t cy2)
{
int32_t n, nn, z, zz, x, x1, x2, y, y1, y2, t;
-
+
nn = 0;
z = 0;
do
{
zz = ((z+1)&3);
- x1 = rx1[z];
- x2 = rx1[zz]-x1;
+
+
+ x1 = pvWalls[z] .cameraSpaceCoo[0][VEC_X];
+ x2 = pvWalls[zz].cameraSpaceCoo[0][VEC_X]-x1;
- if ((cx1 <= x1) && (x1 <= cx2))
- rx2[nn] = x1, ry2[nn] = ry1[z], nn++;
-
- if (x2 <= 0) x = cx2;
- else x = cx1;
+ if ((cx1 <= x1) && (x1 <= cx2)){
+ pvWalls[nn] .cameraSpaceCoo[1][VEC_X] = x1;
+ pvWalls[nn] .cameraSpaceCoo[1][VEC_Y] = pvWalls[z] .cameraSpaceCoo[0][VEC_Y];
+ nn++;
+ }
+
+ if (x2 <= 0)
+ x = cx2;
+ else
+ x = cx1;
+
t = x-x1;
- if (((t-x2)^t) < 0)
- rx2[nn] = x, ry2[nn] = ry1[z]+scale(t,ry1[zz]-ry1[z],x2), nn++;
-
- if (x2 <= 0) x = cx1;
- else x = cx2;
+
+ if (((t-x2)^t) < 0){
+ pvWalls[nn] .cameraSpaceCoo[1][VEC_X] = x;
+ pvWalls[nn] .cameraSpaceCoo[1][VEC_Y] = pvWalls[z].cameraSpaceCoo[0][VEC_Y] +
+ scale(t,pvWalls[zz].cameraSpaceCoo[0][VEC_Y]-pvWalls[z].cameraSpaceCoo[0][VEC_Y],x2);
+ nn++;
+ }
+
+ if (x2 <= 0)
+ x = cx1;
+ else
+ x = cx2;
+
t = x-x1;
- if (((t-x2)^t) < 0)
- rx2[nn] = x, ry2[nn] = ry1[z]+scale(t,ry1[zz]-ry1[z],x2), nn++;
-
+
+ if (((t-x2)^t) < 0){
+ pvWalls[nn] .cameraSpaceCoo[1][VEC_X] = x;
+ pvWalls[nn] .cameraSpaceCoo[1][VEC_Y] = pvWalls[z] .cameraSpaceCoo[0][VEC_Y]+
+ scale(t,pvWalls[zz].cameraSpaceCoo[0][VEC_Y]-pvWalls[z].cameraSpaceCoo[0][VEC_Y],x2);
+ nn++;
+ }
z = zz;
} while (z != 0);
if (nn < 3) return(0);
@@ -3720,25 +3735,40 @@
do
{
zz = z+1;
- if (zz == nn) zz = 0;
- y1 = ry2[z];
- y2 = ry2[zz]-y1;
+ if (zz == nn)
+ zz = 0;
+
+ y1 = pvWalls[z] .cameraSpaceCoo[1][VEC_Y];
+ y2 = pvWalls[zz].cameraSpaceCoo[1][VEC_Y]-y1;
- if ((cy1 <= y1) && (y1 <= cy2))
- ry1[n] = y1, rx1[n] = rx2[z], n++;
-
+ if ((cy1 <= y1) && (y1 <= cy2)){
+ pvWalls[n] .cameraSpaceCoo[0][VEC_Y] = y1;
+ pvWalls[n] .cameraSpaceCoo[0][VEC_X] = pvWalls[z] .cameraSpaceCoo[1][VEC_X];
+ n++;
+ }
if (y2 <= 0) y = cy2;
else y = cy1;
t = y-y1;
- if (((t-y2)^t) < 0)
- ry1[n] = y, rx1[n] = rx2[z]+scale(t,rx2[zz]-rx2[z],y2), n++;
-
+ if (((t-y2)^t) < 0){
+ pvWalls[n] .cameraSpaceCoo[0][VEC_Y] = y;
+ pvWalls[n] .cameraSpaceCoo[0][VEC_X] =
+ pvWalls[z] .cameraSpaceCoo[1][VEC_X]+scale(t,
+ pvWalls[zz].cameraSpaceCoo[1][VEC_X]-
+ pvWalls[z] .cameraSpaceCoo[1][VEC_X],y2);
+ n++;
+ }
+
if (y2 <= 0) y = cy1;
else y = cy2;
t = y-y1;
- if (((t-y2)^t) < 0)
- ry1[n] = y, rx1[n] = rx2[z]+scale(t,rx2[zz]-rx2[z],y2), n++;
-
+ if (((t-y2)^t) < 0){
+ pvWalls[n] .cameraSpaceCoo[0][VEC_Y] = y;
+ pvWalls[n] .cameraSpaceCoo[0][VEC_X] =
+ pvWalls[z] .cameraSpaceCoo[1][VEC_X]+scale(t,
+ pvWalls[zz].cameraSpaceCoo[1][VEC_X]-
+ pvWalls[z ].cameraSpaceCoo[1][VEC_X],y2);
+ n++;
+ }
z = zz;
} while (z != 0);
return(n);
@@ -3814,39 +3844,76 @@
yv2 = yv;
}
- ry1[0] = sy - (yv*xoff + xv*yoff);
- ry1[1] = ry1[0] + yv * tileWidht;
- ry1[3] = ry1[0] + xv * tileHeight;
- ry1[2] = ry1[1]+ry1[3]-ry1[0];
+
+ //Taking care of the Y coordinates.
+ pvWalls[0].cameraSpaceCoo[0][VEC_Y] = sy - (yv*xoff + xv*yoff);
+ pvWalls[1].cameraSpaceCoo[0][VEC_Y] = pvWalls[0].cameraSpaceCoo[0][VEC_Y] + yv * tileWidht;
+ pvWalls[3].cameraSpaceCoo[0][VEC_Y] = pvWalls[0].cameraSpaceCoo[0][VEC_Y] + xv * tileHeight;
+
+ pvWalls[2].cameraSpaceCoo[0][VEC_Y] = pvWalls[1].cameraSpaceCoo[0][VEC_Y] +
+ pvWalls[3].cameraSpaceCoo[0][VEC_Y] -
+ pvWalls[0].cameraSpaceCoo[0][VEC_Y] ;
+
i = (cy1<<16);
- if ((ry1[0]<i) && (ry1[1]<i) && (ry1[2]<i) && (ry1[3]<i)) return;
+
+ if ((pvWalls[0].cameraSpaceCoo[0][VEC_Y]<i) &&
+ (pvWalls[1].cameraSpaceCoo[0][VEC_Y]<i) &&
+ (pvWalls[2].cameraSpaceCoo[0][VEC_Y]<i) &&
+ (pvWalls[3].cameraSpaceCoo[0][VEC_Y]<i))
+ return;
+
i = (cy2<<16);
- if ((ry1[0]>i) && (ry1[1]>i) && (ry1[2]>i) && (ry1[3]>i)) return;
+
+ if ((pvWalls[0].cameraSpaceCoo[0][VEC_Y]>i) &&
+ (pvWalls[1].cameraSpaceCoo[0][VEC_Y]>i) &&
+ (pvWalls[2].cameraSpaceCoo[0][VEC_Y]>i) &&
+ (pvWalls[3].cameraSpaceCoo[0][VEC_Y]>i))
+ return;
- rx1[0] = sx - (xv2*xoff - yv2*yoff);
- rx1[1] = rx1[0] + xv2 * tileWidht;
- rx1[3] = rx1[0] - yv2 * tileHeight;
- rx1[2] = rx1[1]+rx1[3]-rx1[0];
+
+
+ //Taking care of the X coordinates.
+ pvWalls[0].cameraSpaceCoo[0][VEC_X] = sx - (xv2*xoff - yv2*yoff);
+ pvWalls[1].cameraSpaceCoo[0][VEC_X] = pvWalls[0].cameraSpaceCoo[0][VEC_X] + xv2 * tileWidht;
+ pvWalls[3].cameraSpaceCoo[0][VEC_X] = pvWalls[0].cameraSpaceCoo[0][VEC_X] - yv2 * tileHeight;
+ pvWalls[2].cameraSpaceCoo[0][VEC_X] = pvWalls[1].cameraSpaceCoo[0][VEC_X] +
+ pvWalls[3].cameraSpaceCoo[0][VEC_X] -
+ pvWalls[0].cameraSpaceCoo[0][VEC_X] ;
+
i = (cx1<<16);
- if ((rx1[0]<i) && (rx1[1]<i) && (rx1[2]<i) && (rx1[3]<i)) return;
+ if ((pvWalls[0].cameraSpaceCoo[0][VEC_X]<i) &&
+ (pvWalls[1].cameraSpaceCoo[0][VEC_X]<i) &&
+ (pvWalls[2].cameraSpaceCoo[0][VEC_X]<i) &&
+ (pvWalls[3].cameraSpaceCoo[0][VEC_X]<i))
+ return;
+
i = (cx2<<16);
- if ((rx1[0]>i) && (rx1[1]>i) && (rx1[2]>i) && (rx1[3]>i)) return;
+ if ((pvWalls[0].cameraSpaceCoo[0][VEC_X]>i) &&
+ (pvWalls[1].cameraSpaceCoo[0][VEC_X]>i) &&
+ (pvWalls[2].cameraSpaceCoo[0][VEC_X]>i) &&
+ (pvWalls[3].cameraSpaceCoo[0][VEC_X]>i))
+ return;
+
+
+
+
+
- gx1 = rx1[0];
- gy1 = ry1[0]; /* back up these before clipping */
+ gx1 = pvWalls[0].cameraSpaceCoo[0][VEC_X];
+ gy1 = pvWalls[0].cameraSpaceCoo[0][VEC_Y]; /* back up these before clipping */
if ((npoints = clippoly4(cx1<<16,cy1<<16,(cx2+1)<<16,(cy2+1)<<16)) < 3) return;
- lx = rx1[0];
- rx = rx1[0];
+ lx = pvWalls[0].cameraSpaceCoo[0][VEC_X];
+ rx = pvWalls[0].cameraSpaceCoo[0][VEC_X];
nextv = 0;
for(v=npoints-1; v>=0; v--)
{
- x1 = rx1[v];
- x2 = rx1[nextv];
+ x1 = pvWalls[ v].cameraSpaceCoo[0][VEC_X];
+ x2 = pvWalls[nextv].cameraSpaceCoo[0][VEC_X];
dax1 = (x1>>16);
if (x1 < lx) lx = x1;
dax2 = (x2>>16);
@@ -3853,8 +3920,8 @@
if (x1 > rx) rx = x1;
if (dax1 != dax2)
{
- y1 = ry1[v];
- y2 = ry1[nextv];
+ y1 = pvWalls[ v].cameraSpaceCoo[0][VEC_Y];
+ y2 = pvWalls[nextv].cameraSpaceCoo[0][VEC_Y];
yinc = divscale16(y2-y1,x2-x1);
if (dax2 > dax1)
{
@@ -3870,7 +3937,7 @@
nextv = v;
}
- TILE_MakeAvailable(globalpicnum);
+ TILE_MakeAvailable(picnum);
setgotpic(picnum);
bufplc = tiles[picnum].data;
@@ -4561,24 +4628,37 @@
sectortype *sec, *nsec;
walltype *wal;
+ //Retrive pvWall ID.
z = maskwall[damaskwallcnt];
- wal = &wall[thewall[z]];
- sectnum = thesector[z];
+
+ //Retrive world wall ID.
+ wal = &wall[pvWalls[z].worldWallId];
+
+ //Retrive sector ID
+ sectnum = pvWalls[z].sectorId;
+
+ //Retrive sector.
sec = §or[sectnum];
+
+ //Retrive next sector.
nsec = §or[wal->nextsector];
+
z1 = max(nsec->ceilingz,sec->ceilingz);
z2 = min(nsec->floorz,sec->floorz);
wallmost(uwall,z,sectnum,(uint8_t )0);
wallmost(uplc,z,(int32_t)wal->nextsector,(uint8_t )0);
- for(x=xb1[z]; x<=xb2[z]; x++)
+ for(x=pvWalls[z].screenSpaceCoo[0][VEC_COL]; x<=pvWalls[z].screenSpaceCoo[1][VEC_COL]; x++)
if (uplc[x] > uwall[x])
uwall[x] = uplc[x];
+
wallmost(dwall,z,sectnum,(uint8_t )1);
wallmost(dplc,z,(int32_t)wal->nextsector,(uint8_t )1);
- for(x=xb1[z]; x<=xb2[z]; x++)
+ for(x=pvWalls[z].screenSpaceCoo[0][VEC_COL]; x<=pvWalls[z].screenSpaceCoo[1][VEC_COL]; x++)
if (dplc[x] < dwall[x])
dwall[x] = dplc[x];
+
+
prepwall(z,wal);
globalorientation = (int32_t)wal->cstat;
@@ -4612,11 +4692,11 @@
for(i=smostwallcnt-1; i>=0; i--)
{
j = smostwall[i];
- if ((xb1[j] > xb2[z]) || (xb2[j] < xb1[z])) continue;
+ if ((pvWalls[j].screenSpaceCoo[0][VEC_COL] > pvWalls[z].screenSpaceCoo[1][VEC_COL]) || (pvWalls[j].screenSpaceCoo[1][VEC_COL] < pvWalls[z].screenSpaceCoo[0][VEC_COL])) continue;
if (wallfront(j,z)) continue;
- lx = max(xb1[j],xb1[z]);
- rx = min(xb2[j],xb2[z]);
+ lx = max(pvWalls[j].screenSpaceCoo[0][VEC_COL],pvWalls[z].screenSpaceCoo[0][VEC_COL]);
+ rx = min(pvWalls[j].screenSpaceCoo[1][VEC_COL],pvWalls[z].screenSpaceCoo[1][VEC_COL]);
switch(smostwalltype[i])
{
@@ -4623,17 +4703,17 @@
case 0:
if (lx <= rx)
{
- if ((lx == xb1[z]) && (rx == xb2[z])) return;
+ if ((lx == pvWalls[z].screenSpaceCoo[0][VEC_COL]) && (rx == pvWalls[z].screenSpaceCoo[1][VEC_COL])) return;
clearbufbyte(&dwall[lx],(rx-lx+1)*sizeof(dwall[0]),0L);
}
break;
case 1:
- k = smoststart[i] - xb1[j];
+ k = smoststart[i] - pvWalls[j].screenSpaceCoo[0][VEC_COL];
for(x=lx; x<=rx; x++)
if (smost[k+x] > uwall[x]) uwall[x] = smost[k+x];
break;
case 2:
- k = smoststart[i] - xb1[j];
+ k = smoststart[i] - pvWalls[j].screenSpaceCoo[0][VEC_COL];
for(x=lx; x<=rx; x++)
if (smost[k+x] < dwall[x]) dwall[x] = smost[k+x];
break;
@@ -4641,17 +4721,17 @@
}
/* maskwall */
- if ((searchit >= 1) && (searchx >= xb1[z]) && (searchx <= xb2[z]))
+ if ((searchit >= 1) && (searchx >= pvWalls[z].screenSpaceCoo[0][VEC_COL]) && (searchx <= pvWalls[z].screenSpaceCoo[1][VEC_COL]))
if ((searchy >= uwall[searchx]) && (searchy <= dwall[searchx]))
{
searchsector = sectnum;
- searchwall = thewall[z];
+ searchwall = pvWalls[z].worldWallId;
searchstat = 4;
searchit = 1;
}
if ((globalorientation&128) == 0)
- maskwallscan(xb1[z],xb2[z],uwall,dwall,swall,lwall);
+ maskwallscan(pvWalls[z].screenSpaceCoo[0][VEC_COL],pvWalls[z].screenSpaceCoo[1][VEC_COL],uwall,dwall,swall,lwall);
else
{
if (globalorientation&128)
@@ -4661,7 +4741,7 @@
else
settrans(TRANS_NORMAL);
}
- transmaskwallscan(xb1[z],xb2[z]);
+ transmaskwallscan(pvWalls[z].screenSpaceCoo[0][VEC_COL],pvWalls[z].screenSpaceCoo[1][VEC_COL]);
}
}
@@ -4884,17 +4964,17 @@
continue;
j = smostwall[i];
- if ((xb1[j] > rx) || (xb2[j] < lx))
+ if ((pvWalls[j].screenSpaceCoo[0][VEC_COL] > rx) || (pvWalls[j].screenSpaceCoo[1][VEC_COL] < lx))
continue;
- if ((yp <= yb1[j]) && (yp <= yb2[j]))
+ if ((yp <= pvWalls[j].screenSpaceCoo[0][VEC_DIST]) && (yp <= pvWalls[j].screenSpaceCoo[1][VEC_DIST]))
continue;
- if (spritewallfront(tspr,(int32_t)thewall[j]) && ((yp <= yb1[j]) || (yp <= yb2[j])))
+ if (spritewallfront(tspr,pvWalls[j].worldWallId) && ((yp <= pvWalls[j].screenSpaceCoo[0][VEC_DIST]) || (yp <= pvWalls[j].screenSpaceCoo[1][VEC_DIST])))
continue;
- dalx2 = max(xb1[j],lx);
- darx2 = min(xb2[j],rx);
+ dalx2 = max(pvWalls[j].screenSpaceCoo[0][VEC_COL],lx);
+ darx2 = min(pvWalls[j].screenSpaceCoo[1][VEC_COL],rx);
switch(smostwalltype[i])
{
@@ -4907,13 +4987,13 @@
}
break;
case 1:
- k = smoststart[i] - xb1[j];
+ k = smoststart[i] - pvWalls[j].screenSpaceCoo[0][VEC_COL];
for(x=dalx2; x<=darx2; x++)
if (smost[k+x] > uwall[x]) uwall[x] = smost[k+x];
if ((dalx2 == lx) && (darx2 == rx)) daclip |= 1;
break;
case 2:
- k = smoststart[i] - xb1[j];
+ k = smoststart[i] - pvWalls[j].screenSpaceCoo[0][VEC_COL];
for(x=dalx2; x<=darx2; x++)
if (smost[k+x] < dwall[x]) dwall[x] = smost[k+x];
if ((dalx2 == lx) && (darx2 == rx)) daclip |= 2;
@@ -5017,18 +5097,18 @@
if (xp1 > yp1) return;
if (yp1 == 0) return;
- xb1[MAXWALLSB-1] = halfxdimen + scale(xp1,halfxdimen,yp1);
- if (xp1 >= 0) xb1[MAXWALLSB-1]++; /* Fix for SIGNED divide */
- if (xb1[MAXWALLSB-1] >= xdimen) xb1[MAXWALLSB-1] = xdimen-1;
- yb1[MAXWALLSB-1] = yp1;
+ pvWalls[MAXWALLSB-1].screenSpaceCoo[0][VEC_COL] = halfxdimen + scale(xp1,halfxdimen,yp1);
+ if (xp1 >= 0) pvWalls[MAXWALLSB-1].screenSpaceCoo[0][VEC_COL]++; /* Fix for SIGNED divide */
+ if (pvWalls[MAXWALLSB-1].screenSpaceCoo[0][VEC_COL] >= xdimen) pvWalls[MAXWALLSB-1].screenSpaceCoo[0][VEC_COL] = xdimen-1;
+ pvWalls[MAXWALLSB-1].screenSpaceCoo[0][VEC_DIST] = yp1;
}
else
{
if (xp2 < -yp2) return;
- xb1[MAXWALLSB-1] = 0;
+ pvWalls[MAXWALLSB-1].screenSpaceCoo[0][VEC_COL] = 0;
i = yp1-yp2+xp1-xp2;
if (i == 0) return;
- yb1[MAXWALLSB-1] = yp1 + scale(yp2-yp1,xp1+yp1,i);
+ pvWalls[MAXWALLSB-1].screenSpaceCoo[0][VEC_DIST] = yp1 + scale(yp2-yp1,xp1+yp1,i);
}
if (xp2 <= yp2)
{
@@ -5035,33 +5115,33 @@
if (xp2 < -yp2) return;
if (yp2 == 0) return;
- xb2[MAXWALLSB-1] = halfxdimen + scale(xp2,halfxdimen,yp2) - 1;
- if (xp2 >= 0) xb2[MAXWALLSB-1]++; /* Fix for SIGNED divide */
- if (xb2[MAXWALLSB-1] >= xdimen) xb2[MAXWALLSB-1] = xdimen-1;
- yb2[MAXWALLSB-1] = yp2;
+ pvWalls[MAXWALLSB-1].screenSpaceCoo[1][VEC_COL] = halfxdimen + scale(xp2,halfxdimen,yp2) - 1;
+ if (xp2 >= 0) pvWalls[MAXWALLSB-1].screenSpaceCoo[1][VEC_COL]++; /* Fix for SIGNED divide */
+ if (pvWalls[MAXWALLSB-1].screenSpaceCoo[1][VEC_COL] >= xdimen) pvWalls[MAXWALLSB-1].screenSpaceCoo[1][VEC_COL] = xdimen-1;
+ pvWalls[MAXWALLSB-1].screenSpaceCoo[1][VEC_DIST] = yp2;
}
else
{
if (xp1 > yp1) return;
- xb2[MAXWALLSB-1] = xdimen-1;
+ pvWalls[MAXWALLSB-1].screenSpaceCoo[1][VEC_COL] = xdimen-1;
i = xp2-xp1+yp1-yp2;
if (i == 0) return;
- yb2[MAXWALLSB-1] = yp1 + scale(yp2-yp1,yp1-xp1,i);
+ pvWalls[MAXWALLSB-1].screenSpaceCoo[1][VEC_DIST] = yp1 + scale(yp2-yp1,yp1-xp1,i);
}
- if ((yb1[MAXWALLSB-1] < 256) || (yb2[MAXWALLSB-1] < 256) || (xb1[MAXWALLSB-1] > xb2[MAXWALLSB-1]))
+ if ((pvWalls[MAXWALLSB-1].screenSpaceCoo[0][VEC_DIST] < 256) || (pvWalls[MAXWALLSB-1].screenSpaceCoo[1][VEC_DIST] < 256) || (pvWalls[MAXWALLSB-1].screenSpaceCoo[0][VEC_COL] > pvWalls[MAXWALLSB-1].screenSpaceCoo[1][VEC_COL]))
return;
topinc = -mulscale10(yp1,spriteDim.width);
- top = (((mulscale10(xp1,xdimen) - mulscale9(xb1[MAXWALLSB-1]-halfxdimen,yp1))*spriteDim.width)>>3);
+ top = (((mulscale10(xp1,xdimen) - mulscale9(pvWalls[MAXWALLSB-1].screenSpaceCoo[0][VEC_COL]-halfxdimen,yp1))*spriteDim.width)>>3);
botinc = ((yp2-yp1)>>8);
- bot = mulscale11(xp1-xp2,xdimen) + mulscale2(xb1[MAXWALLSB-1]-halfxdimen,botinc);
+ bot = mulscale11(xp1-xp2,xdimen) + mulscale2(pvWalls[MAXWALLSB-1].screenSpaceCoo[0][VEC_COL]-halfxdimen,botinc);
- j = xb2[MAXWALLSB-1]+3;
+ j = pvWalls[MAXWALLSB-1].screenSpaceCoo[1][VEC_COL]+3;
z = mulscale20(top,krecipasm(bot));
- lwall[xb1[MAXWALLSB-1]] = (z>>8);
- for(x=xb1[MAXWALLSB-1]+4; x<=j; x+=4)
+ lwall[pvWalls[MAXWALLSB-1].screenSpaceCoo[0][VEC_COL]] = (z>>8);
+ for(x=pvWalls[MAXWALLSB-1].screenSpaceCoo[0][VEC_COL]+4; x<=j; x+=4)
{
top += topinc;
bot += botinc;
@@ -5074,24 +5154,25 @@
lwall[x-1] = ((i+z)>>9);
}
- if (lwall[xb1[MAXWALLSB-1]] < 0) lwall[xb1[MAXWALLSB-1]] = 0;
- if (lwall[xb2[MAXWALLSB-1]] >= spriteDim.width) lwall[xb2[MAXWALLSB-1]] = spriteDim.width-1;
+ if (lwall[pvWalls[MAXWALLSB-1].screenSpaceCoo[0][VEC_COL]] < 0) lwall[pvWalls[MAXWALLSB-1].screenSpaceCoo[0][VEC_COL]] = 0;
+ if (lwall[pvWalls[MAXWALLSB-1].screenSpaceCoo[1][VEC_COL]] >= spriteDim.width) lwall[pvWalls[MAXWALLSB-1].screenSpaceCoo[1][VEC_COL]] = spriteDim.width-1;
if ((swapped^((cstat&4)>0)) > 0)
{
j = spriteDim.width-1;
- for(x=xb1[MAXWALLSB-1]; x<=xb2[MAXWALLSB-1]; x++)
+ for(x=pvWalls[MAXWALLSB-1].screenSpaceCoo[0][VEC_COL]; x<=pvWalls[MAXWALLSB-1].screenSpaceCoo[1][VEC_COL]; x++)
lwall[x] = j-lwall[x];
}
- rx1[MAXWALLSB-1] = xp1;
- ry1[MAXWALLSB-1] = yp1;
- rx2[MAXWALLSB-1] = xp2;
- ry2[MAXWALLSB-1] = yp2;
+ pvWalls[MAXWALLSB-1].cameraSpaceCoo[0][VEC_X] = xp1 ;
+ pvWalls[MAXWALLSB-1].cameraSpaceCoo[0][VEC_Y] = yp1 ;
+ pvWalls[MAXWALLSB-1].cameraSpaceCoo[1][VEC_X] = xp2 ;
+ pvWalls[MAXWALLSB-1].cameraSpaceCoo[1][VEC_Y] = yp2 ;
- hplc = divscale19(xdimenscale,yb1[MAXWALLSB-1]);
- hinc = divscale19(xdimenscale,yb2[MAXWALLSB-1]);
- hinc = (hinc-hplc)/(xb2[MAXWALLSB-1]-xb1[MAXWALLSB-1]+1);
+
+ hplc = divscale19(xdimenscale,pvWalls[MAXWALLSB-1].screenSpaceCoo[0][VEC_DIST]);
+ hinc = divscale19(xdimenscale,pvWalls[MAXWALLSB-1].screenSpaceCoo[1][VEC_DIST]);
+ hinc = (hinc-hplc)/(pvWalls[MAXWALLSB-1].screenSpaceCoo[1][VEC_COL]-pvWalls[MAXWALLSB-1].screenSpaceCoo[0][VEC_COL]+1);
z2 = tspr->z - ((yoff*tspr->yrepeat)<<2);
if (cstat&128)
@@ -5126,7 +5207,7 @@
owallmost(uwall,(int32_t)(MAXWALLSB-1),z1-globalposz);
owallmost(dwall,(int32_t)(MAXWALLSB-1),z2-globalposz);
- for(i=xb1[MAXWALLSB-1]; i<=xb2[MAXWALLSB-1]; i++)
+ for(i=pvWalls[MAXWALLSB-1].screenSpaceCoo[0][VEC_COL]; i<=pvWalls[MAXWALLSB-1].screenSpaceCoo[1][VEC_COL]; i++)
{
swall[i] = (krecipasm(hplc)<<2);
hplc += hinc;
@@ -5136,19 +5217,19 @@
{
j = smostwall[i];
- if ((xb1[j] > xb2[MAXWALLSB-1]) || (xb2[j] < xb1[MAXWALLSB-1])) continue;
+ if ((pvWalls[j].screenSpaceCoo[0][VEC_COL] > pvWalls[MAXWALLSB-1].screenSpaceCoo[1][VEC_COL]) || (pvWalls[j].screenSpaceCoo[1][VEC_COL] < pvWalls[MAXWALLSB-1].screenSpaceCoo[0][VEC_COL])) continue;
- dalx2 = xb1[j];
- darx2 = xb2[j];
- if (max(yb1[MAXWALLSB-1],yb2[MAXWALLSB-1]) > min(yb1[j],yb2[j]))
+ dalx2 = pvWalls[j].screenSpaceCoo[0][VEC_COL];
+ darx2 = pvWalls[j].screenSpaceCoo[1][VEC_COL];
+ if (max(pvWalls[MAXWALLSB-1].screenSpaceCoo[0][VEC_DIST],pvWalls[MAXWALLSB-1].screenSpaceCoo[1][VEC_DIST]) > min(pvWalls[j].screenSpaceCoo[0][VEC_DIST],pvWalls[j].screenSpaceCoo[1][VEC_DIST]))
{
- if (min(yb1[MAXWALLSB-1],yb2[MAXWALLSB-1]) > max(yb1[j],yb2[j]))
+ if (min(pvWalls[MAXWALLSB-1].screenSpaceCoo[0][VEC_DIST],pvWalls[MAXWALLSB-1].screenSpaceCoo[1][VEC_DIST]) > max(pvWalls[j].screenSpaceCoo[0][VEC_DIST],pvWalls[j].screenSpaceCoo[1][VEC_DIST]))
{
x = 0x80000000;
}
else
{
- x = thewall[j];
+ x = pvWalls[j].worldWallId;
xp1 = wall[x].x;
yp1 = wall[x].y;
x = wall[x].point2;
@@ -5170,7 +5251,7 @@
{
if ((xp2-xp1)*(tspr->y-yp1) == (tspr->x-xp1)*(yp2-yp1))
{
- if (wall[thewall[j]].nextsector == tspr->sectnum)
+ if (wall[pvWalls[j].worldWallId].nextsector == tspr->sectnum)
x = 0x80000000;
else
x = 0x7fffffff;
@@ -5206,24 +5287,24 @@
}
if (x < 0)
{
- if (dalx2 < xb1[MAXWALLSB-1]) dalx2 = xb1[MAXWALLSB-1];
- if (darx2 > xb2[MAXWALLSB-1]) darx2 = xb2[MAXWALLSB-1];
+ if (dalx2 < pvWalls[MAXWALLSB-1].screenSpaceCoo[0][VEC_COL]) dalx2 = pvWalls[MAXWALLSB-1].screenSpaceCoo[0][VEC_COL];
+ if (darx2 > pvWalls[MAXWALLSB-1].screenSpaceCoo[1][VEC_COL]) darx2 = pvWalls[MAXWALLSB-1].screenSpaceCoo[1][VEC_COL];
switch(smostwalltype[i])
{
case 0:
if (dalx2 <= darx2)
{
- if ((dalx2 == xb1[MAXWALLSB-1]) && (darx2 == xb2[MAXWALLSB-1])) return;
+ if ((dalx2 == pvWalls[MAXWALLSB-1].screenSpaceCoo[0][VEC_COL]) && (darx2 == pvWalls[MAXWALLSB-1].screenSpaceCoo[1][VEC_COL])) return;
clearbufbyte(&dwall[dalx2],(darx2-dalx2+1)*sizeof(dwall[0]),0L);
}
break;
case 1:
- k = smoststart[i] - xb1[j];
+ k = smoststart[i] - pvWalls[j].screenSpaceCoo[0][VEC_COL];
for(x=dalx2; x<=darx2; x++)
if (smost[k+x] > uwall[x]) uwall[x] = smost[k+x];
break;
case 2:
- k = smoststart[i] - xb1[j];
+ k = smoststart[i] - pvWalls[j].screenSpaceCoo[0][VEC_COL];
for(x=dalx2; x<=darx2; x++)
if (smost[k+x] < dwall[x]) dwall[x] = smost[k+x];
break;
@@ -5233,7 +5314,7 @@
}
/* sprite */
- if ((searchit >= 1) && (searchx >= xb1[MAXWALLSB-1]) && (searchx <= xb2[MAXWALLSB-1]))
+ if ((searchit >= 1) && (searchx >= pvWalls[MAXWALLSB-1].screenSpaceCoo[0][VEC_COL]) && (searchx <= pvWalls[MAXWALLSB-1].screenSpaceCoo[1][VEC_COL]))
if ((searchy >= uwall[searchx]) && (searchy <= dwall[searchx]))
{
searchsector = sectnum;
@@ -5243,9 +5324,9 @@
}
if ((cstat&2) == 0)
- maskwallscan(xb1[MAXWALLSB-1],xb2[MAXWALLSB-1],uwall,dwall,swall,lwall);
+ maskwallscan(pvWalls[MAXWALLSB-1].screenSpaceCoo[0][VEC_COL],pvWalls[MAXWALLSB-1].screenSpaceCoo[1][VEC_COL],uwall,dwall,swall,lwall);
else
- transmaskwallscan(xb1[MAXWALLSB-1],xb2[MAXWALLSB-1]);
+ transmaskwallscan(pvWalls[MAXWALLSB-1].screenSpaceCoo[0][VEC_COL],pvWalls[MAXWALLSB-1].screenSpaceCoo[1][VEC_COL]);
}
else if ((cstat&48) == 32)
{
@@ -5511,11 +5592,11 @@
for(i=smostwallcnt-1; i>=0; i--)
{
j = smostwall[i];
- if ((xb1[j] > rx) || (xb2[j] < lx)) continue;
- if ((yp <= yb1[j]) && (yp <= yb2[j])) continue;
+ if ((pvWalls[j].screenSpaceCoo[0][VEC_COL] > rx) || (pvWalls[j].screenSpaceCoo[1][VEC_COL] < lx)) continue;
+ if ((yp <= pvWalls[j].screenSpaceCoo[0][VEC_DIST]) && (yp <= pvWalls[j].screenSpaceCoo[1][VEC_DIST])) continue;
/* if (spritewallfront(tspr,thewall[j]) == 0) */
- x = thewall[j];
+ x = pvWalls[j].worldWallId;
xp1 = wall[x].x;
yp1 = wall[x].y;
x = wall[x].point2;
@@ -5522,11 +5603,11 @@
xp2 = wall[x].x;
yp2 = wall[x].y;
x = (xp2-xp1)*(tspr->y-yp1)-(tspr->x-xp1)*(yp2-yp1);
- if ((yp > yb1[j]) && (yp > yb2[j])) x = -1;
- if ((x >= 0) && ((x != 0) || (wall[thewall[j]].nextsector != tspr->sectnum))) continue;
+ if ((yp > pvWalls[j].screenSpaceCoo[0][VEC_DIST]) && (yp > pvWalls[j].screenSpaceCoo[1][VEC_DIST])) x = -1;
+ if ((x >= 0) && ((x != 0) || (wall[pvWalls[j].worldWallId].nextsector != tspr->sectnum))) continue;
- dalx2 = max(xb1[j],lx);
- darx2 = min(xb2[j],rx);
+ dalx2 = max(pvWalls[j].screenSpaceCoo[0][VEC_COL],lx);
+ darx2 = min(pvWalls[j].screenSpaceCoo[1][VEC_COL],rx);
switch(smostwalltype[i])
{
@@ -5538,12 +5619,12 @@
}
break;
case 1:
- k = smoststart[i] - xb1[j];
+ k = smoststart[i] - pvWalls[j].screenSpaceCoo[0][VEC_COL];
for(x=dalx2; x<=darx2; x++)
if (smost[k+x] > uwall[x]) uwall[x] = smost[k+x];
break;
case 2:
- k = smoststart[i] - xb1[j];
+ k = smoststart[i] - pvWalls[j].screenSpaceCoo[0][VEC_COL];
for(x=dalx2; x<=darx2; x++)
if (smost[k+x] < dwall[x]) dwall[x] = smost[k+x];
break;
@@ -5714,7 +5795,7 @@
while ((spritesortcnt > 0) && (maskwallcnt > 0)) /* While BOTH > 0 */
{
j = maskwall[maskwallcnt-1];
- if (spritewallfront(tspriteptr[spritesortcnt-1],(int32_t)thewall[j]) == 0)
+ if (spritewallfront(tspriteptr[spritesortcnt-1],pvWalls[j].worldWallId) == 0)
drawsprite(--spritesortcnt);
else
{
@@ -5722,8 +5803,8 @@
k = -1;
gap = 0;
for(i=spritesortcnt-2; i>=0; i--)
- if ((xb1[j] <= (spritesx[i]>>8)) && ((spritesx[i]>>8) <= xb2[j]))
- if (spritewallfront(tspriteptr[i],(int32_t)thewall[j]) == 0)
+ if ((pvWalls[j].screenSpaceCoo[0][VEC_COL] <= (spritesx[i]>>8)) && ((spritesx[i]>>8) <= pvWalls[j].screenSpaceCoo[1][VEC_COL]))
+ if (spritewallfront(tspriteptr[i],pvWalls[j].worldWallId) == 0)
{
drawsprite(i);
tspriteptr[i]->owner = -1;
@@ -8188,7 +8269,7 @@
maxy = 0x80000000;
for(z=npoints-1; z>=0; z--)
{
- y = ry1[z];
+ y = pvWalls[z].cameraSpaceCoo[0][VEC_Y];
miny = min(miny,y);
maxy = max(maxy,y);
}
@@ -8206,15 +8287,15 @@
for(z=npoints-1; z>=0; z--)
{
- zz = xb1[z];
- y1 = ry1[z];
+ zz = pvWalls[z].screenSpaceCoo[0][VEC_COL];
+ y1 = pvWalls[z] .cameraSpaceCoo[0][VEC_Y];
day1 = (y1>>12);
- y2 = ry1[zz];
+ y2 = pvWalls[zz].cameraSpaceCoo[0][VEC_Y];
day2 = (y2>>12);
if (day1 != day2)
{
- x1 = rx1[z];
- x2 = rx1[zz];
+ x1 = pvWalls[z ].cameraSpaceCoo[0][VEC_X];
+ x2 = pvWalls[zz].cameraSpaceCoo[0][VEC_X];
xinc = divscale12(x2-x1,y2-y1);
if (day2 > day1)
{
@@ -8321,38 +8402,42 @@
splitcnt = 0;
do
{
- s2 = cx1-rx1[z];
+ s2 = cx1-pvWalls[z].cameraSpaceCoo[0][VEC_X];
do
{
- zz = xb1[z];
- xb1[z] = -1;
+ zz = pvWalls[z].screenSpaceCoo[0][VEC_COL];
+ pvWalls[z].screenSpaceCoo[0][VEC_COL] = -1;
s1 = s2;
- s2 = cx1-rx1[zz];
- if (s1 < 0)
- {
- rx2[npoints2] = rx1[z];
- ry2[npoints2] = ry1[z];
- xb2[npoints2] = npoints2+1;
+ s2 = cx1-pvWalls[zz].cameraSpaceCoo[0][VEC_X];
+ if (s1 < 0){
+ pvWalls[npoints2].cameraSpaceCoo[1][VEC_X] = pvWalls[zz].cameraSpaceCoo[0][VEC_X];
+ pvWalls[npoints2].cameraSpaceCoo[1][VEC_Y] = pvWalls[zz].cameraSpaceCoo[0][VEC_Y];
+ pvWalls[npoints2].screenSpaceCoo[1][VEC_COL] = npoints2+1;
npoints2++;
}
- if ((s1^s2) < 0)
- {
- rx2[npoints2] = rx1[z]+scale(rx1[zz]-rx1[z],s1,s1-s2);
- ry2[npoints2] = ry1[z]+scale(ry1[zz]-ry1[z],s1,s1-s2);
- if (s1 < 0) p2[splitcnt++] = npoints2;
- xb2[npoints2] = npoints2+1;
+
+ if ((s1^s2) < 0){
+ pvWalls[npoints2].cameraSpaceCoo[1][VEC_X] =
+ pvWalls[z].cameraSpaceCoo[0][VEC_X]+scale(pvWalls[zz].cameraSpaceCoo[0][VEC_X]-pvWalls[z].cameraSpaceCoo[0][VEC_X],s1,s1-s2);
+ pvWalls[npoints2].cameraSpaceCoo[1][VEC_Y] =
+ pvWalls[z].cameraSpaceCoo[0][VEC_Y]+scale(pvWalls[zz].cameraSpaceCoo[0][VEC_Y]-pvWalls[z].cameraSpaceCoo[0][VEC_Y],s1,s1-s2);
+
+ if (s1 < 0)
+ bunchWallsList[splitcnt++] = npoints2;
+
+ pvWalls[npoints2].screenSpaceCoo[1][VEC_COL] = npoints2+1;
npoints2++;
}
z = zz;
- } while (xb1[z] >= 0);
+ } while (pvWalls[z].screenSpaceCoo[0][VEC_COL] >= 0);
if (npoints2 >= start2+3)
- xb2[npoints2-1] = start2, start2 = npoints2;
+ pvWalls[npoints2-1].screenSpaceCoo[1][VEC_COL] = start2, start2 = npoints2;
else
npoints2 = start2;
z = 1;
- while ((z < npoints) && (xb1[z] < 0)) z++;
+ while ((z < npoints) && (pvWalls[z].screenSpaceCoo[0][VEC_COL] < 0)) z++;
} while (z < npoints);
if (npoints2 <= 2) return(0);
@@ -8359,19 +8444,19 @@
for(z=1; z<splitcnt; z++)
for(zz=0; zz<z; zz++)
{
- z1 = p2[z];
- z2 = xb2[z1];
- z3 = p2[zz];
- z4 = xb2[z3];
- s1 = klabs(rx2[z1]-rx2[z2])+klabs(ry2[z1]-ry2[z2]);
- s1 += klabs(rx2[z3]-rx2[z4])+klabs(ry2[z3]-ry2[z4]);
- s2 = klabs(rx2[z1]-rx2[z4])+klabs(ry2[z1]-ry2[z4]);
- s2 += klabs(rx2[z3]-rx2[z2])+klabs(ry2[z3]-ry2[z2]);
+ z1 = bunchWallsList[z];
+ z2 = pvWalls[z1].screenSpaceCoo[1][VEC_COL];
+ z3 = bunchWallsList[zz];
+ z4 = pvWalls[z3].screenSpaceCoo[1][VEC_COL];
+ s1 = klabs(pvWalls[z1].cameraSpaceCoo[1][VEC_X]-pvWalls[z2].cameraSpaceCoo[1][VEC_X])+klabs(pvWalls[z1].cameraSpaceCoo[1][VEC_Y]-pvWalls[z2].cameraSpaceCoo[1][VEC_Y]);
+ s1 += klabs(pvWalls[z3].cameraSpaceCoo[1][VEC_X]-pvWalls[z4].cameraSpaceCoo[1][VEC_X])+klabs(pvWalls[z3].cameraSpaceCoo[1][VEC_Y]-pvWalls[z4].cameraSpaceCoo[1][VEC_Y]);
+ s2 = klabs(pvWalls[z1].cameraSpaceCoo[1][VEC_X]-pvWalls[z4].cameraSpaceCoo[1][VEC_X])+klabs(pvWalls[z1].cameraSpaceCoo[1][VEC_Y]-pvWalls[z4].cameraSpaceCoo[1][VEC_Y]);
+ s2 += klabs(pvWalls[z3].cameraSpaceCoo[1][VEC_X]-pvWalls[z2].cameraSpaceCoo[1][VEC_X])+klabs(pvWalls[z3].cameraSpaceCoo[1][VEC_Y]-pvWalls[z2].cameraSpaceCoo[1][VEC_Y]);
if (s2 < s1)
{
- t = xb2[p2[z]];
- xb2[p2[z]] = xb2[p2[zz]];
- xb2[p2[zz]] = t;
+ t = pvWalls[bunchWallsList[z]].screenSpaceCoo[1][VEC_COL];
+ pvWalls[bunchWallsList[z]].screenSpaceCoo[1][VEC_COL] = pvWalls[bunchWallsList[zz]].screenSpaceCoo[1][VEC_COL];
+ pvWalls[bunchWallsList[zz]].screenSpaceCoo[1][VEC_COL] = t;
}
}
@@ -8382,38 +8467,38 @@
splitcnt = 0;
do
{
- s2 = cy1-ry2[z];
+ s2 = cy1-pvWalls[z].cameraSpaceCoo[1][VEC_Y];
do
{
- zz = xb2[z];
- xb2[z] = -1;
+ zz = pvWalls[z].screenSpaceCoo[1][VEC_COL];
+ pvWalls[z].screenSpaceCoo[1][VEC_COL] = -1;
s1 = s2;
- s2 = cy1-ry2[zz];
+ s2 = cy1-pvWalls[zz].cameraSpaceCoo[1][VEC_Y];
if (s1 < 0)
{
- rx1[npoints] = rx2[z];
- ry1[npoints] = ry2[z];
- xb1[npoints] = npoints+1;
+ pvWalls[npoints].cameraSpaceCoo[0][VEC_X] = pvWalls[z].cameraSpaceCoo[1][VEC_X];
+ pvWalls[npoints].cameraSpaceCoo[0][VEC_Y] = pvWalls[z].cameraSpaceCoo[1][VEC_Y];
+ pvWalls[npoints].screenSpaceCoo[0][VEC_COL] = npoints+1;
npoints++;
}
if ((s1^s2) < 0)
{
- rx1[npoints] = rx2[z]+scale(rx2[zz]-rx2[z],s1,s1-s2);
- ry1[npoints] = ry2[z]+scale(ry2[zz]-ry2[z],s1,s1-s2);
- if (s1 < 0) p2[splitcnt++] = npoints;
- xb1[npoints] = npoints+1;
+ pvWalls[npoints].cameraSpaceCoo[0][VEC_X] = pvWalls[z].cameraSpaceCoo[1][VEC_X]+scale(pvWalls[zz].cameraSpaceCoo[1][VEC_X]-pvWalls[z].cameraSpaceCoo[1][VEC_X],s1,s1-s2);
+ pvWalls[npoints].cameraSpaceCoo[0][VEC_Y] = pvWalls[z].cameraSpaceCoo[1][VEC_Y]+scale(pvWalls[zz].cameraSpaceCoo[1][VEC_Y]-pvWalls[z].cameraSpaceCoo[1][VEC_Y],s1,s1-s2);
+ if (s1 < 0) bunchWallsList[splitcnt++] = npoints;
+ pvWalls[npoints].screenSpaceCoo[0][VEC_COL] = npoints+1;
npoints++;
}
z = zz;
- } while (xb2[z] >= 0);
+ } while (pvWalls[z].screenSpaceCoo[1][VEC_COL] >= 0);
if (npoints >= start2+3)
- xb1[npoints-1] = start2, start2 = npoints;
+ pvWalls[npoints-1].screenSpaceCoo[0][VEC_COL] = start2, start2 = npoints;
else
npoints = start2;
z = 1;
- while ((z < npoints2) && (xb2[z] < 0)) z++;
+ while ((z < npoints2) && (pvWalls[z].screenSpaceCoo[1][VEC_COL] < 0)) z++;
} while (z < npoints2);
if (npoints <= 2) return(0);
@@ -8420,19 +8505,19 @@
for(z=1; z<splitcnt; z++)
for(zz=0; zz<z; zz++)
{
- z1 = p2[z];
- z2 = xb1[z1];
- z3 = p2[zz];
- z4 = xb1[z3];
- s1 = klabs(rx1[z1]-rx1[z2])+klabs(ry1[z1]-ry1[z2]);
- s1 += klabs(rx1[z3]-rx1[z4])+klabs(ry1[z3]-ry1[z4]);
- s2 = klabs(rx1[z1]-rx1[z4])+klabs(ry1[z1]-ry1[z4]);
- s2 += klabs(rx1[z3]-rx1[z2])+klabs(ry1[z3]-ry1[z2]);
+ z1 = bunchWallsList[z];
+ z2 = pvWalls[z1].screenSpaceCoo[0][VEC_COL];
+ z3 = bunchWallsList[zz];
+ z4 = pvWalls[z3].screenSpaceCoo[0][VEC_COL];
+ s1 = klabs(pvWalls[z1].cameraSpaceCoo[0][VEC_X]-pvWalls[z2].cameraSpaceCoo[0][VEC_X])+klabs(pvWalls[z1].cameraSpaceCoo[0][VEC_Y]-pvWalls[z2].cameraSpaceCoo[0][VEC_Y]);
+ s1 += klabs(pvWalls[z3].cameraSpaceCoo[0][VEC_X]-pvWalls[z4].cameraSpaceCoo[0][VEC_X])+klabs(pvWalls[z3].cameraSpaceCoo[0][VEC_Y]-pvWalls[z4].cameraSpaceCoo[0][VEC_Y]);
+ s2 = klabs(pvWalls[z1].cameraSpaceCoo[0][VEC_X]-pvWalls[z4].cameraSpaceCoo[0][VEC_X])+klabs(pvWalls[z1].cameraSpaceCoo[0][VEC_Y]-pvWalls[z4].cameraSpaceCoo[0][VEC_Y]);
+ s2 += klabs(pvWalls[z3].cameraSpaceCoo[0][VEC_X]-pvWalls[z2].cameraSpaceCoo[0][VEC_X])+klabs(pvWalls[z3].cameraSpaceCoo[0][VEC_Y]-pvWalls[z2].cameraSpaceCoo[0][VEC_Y]);
if (s2 < s1)
{
- t = xb1[p2[z]];
- xb1[p2[z]] = xb1[p2[zz]];
- xb1[p2[zz]] = t;
+ t = pvWalls[bunchWallsList[z]].screenSpaceCoo[0][VEC_COL];
+ pvWalls[bunchWallsList[z]].screenSpaceCoo[0][VEC_COL] = pvWalls[bunchWallsList[zz]].screenSpaceCoo[0][VEC_COL];
+ pvWalls[bunchWallsList[zz]].screenSpaceCoo[0][VEC_COL] = t;
}
}
}
@@ -8444,38 +8529,38 @@
splitcnt = 0;
do
{
- s2 = rx1[z]-cx2;
+ s2 = pvWalls[z].cameraSpaceCoo[0][VEC_X]-cx2;
do
{
- zz = xb1[z];
- xb1[z] = -1;
+ zz = pvWalls[z].screenSpaceCoo[0][VEC_COL];
+ pvWalls[z].screenSpaceCoo[0][VEC_COL] = -1;
s1 = s2;
- s2 = rx1[zz]-cx2;
+ s2 = pvWalls[zz].cameraSpaceCoo[0][VEC_X]-cx2;
if (s1 < 0)
{
- rx2[npoints2] = rx1[z];
- ry2[npoints2] = ry1[z];
- xb2[npoints2] = npoints2+1;
+ pvWalls[npoints2].cameraSpaceCoo[1][VEC_X] = pvWalls[z].cameraSpaceCoo[0][VEC_X];
+ pvWalls[npoints2].cameraSpaceCoo[1][VEC_Y] = pvWalls[z].cameraSpaceCoo[0][VEC_Y];
+ pvWalls[npoints2].screenSpaceCoo[1][VEC_COL] = npoints2+1;
npoints2++;
}
if ((s1^s2) < 0)
{
- rx2[npoints2] = rx1[z]+scale(rx1[zz]-rx1[z],s1,s1-s2);
- ry2[npoints2] = ry1[z]+scale(ry1[zz]-ry1[z],s1,s1-s2);
- if (s1 < 0) p2[splitcnt++] = npoints2;
- xb2[npoints2] = npoints2+1;
+ pvWalls[npoints2].cameraSpaceCoo[1][VEC_X] = pvWalls[z].cameraSpaceCoo[0][VEC_X]+scale(pvWalls[zz].cameraSpaceCoo[0][VEC_X]-pvWalls[z].cameraSpaceCoo[0][VEC_X],s1,s1-s2);
+ pvWalls[npoints2].cameraSpaceCoo[1][VEC_Y] = pvWalls[z].cameraSpaceCoo[0][VEC_Y]+scale(pvWalls[zz].cameraSpaceCoo[0][VEC_Y]-pvWalls[z].cameraSpaceCoo[0][VEC_Y],s1,s1-s2);
+ if (s1 < 0) bunchWallsList[splitcnt++] = npoints2;
+ pvWalls[npoints2].screenSpaceCoo[1][VEC_COL] = npoints2+1;
npoints2++;
}
z = zz;
- } while (xb1[z] >= 0);
+ } while (pvWalls[z].screenSpaceCoo[0][VEC_COL] >= 0);
if (npoints2 >= start2+3)
- xb2[npoints2-1] = start2, start2 = npoints2;
+ pvWalls[npoints2-1].screenSpaceCoo[1][VEC_COL] = start2, start2 = npoints2;
else
npoints2 = start2;
z = 1;
- while ((z < npoints) && (xb1[z] < 0)) z++;
+ while ((z < npoints) && (pvWalls[z].screenSpaceCoo[0][VEC_COL] < 0)) z++;
} while (z < npoints);
if (npoints2 <= 2) return(0);
@@ -8482,19 +8567,19 @@
for(z=1; z<splitcnt; z++)
for(zz=0; zz<z; zz++)
{
- z1 = p2[z];
- z2 = xb2[z1];
- z3 = p2[zz];
- z4 = xb2[z3];
- s1 = klabs(rx2[z1]-rx2[z2])+klabs(ry2[z1]-ry2[z2]);
- s1 += klabs(rx2[z3]-rx2[z4])+klabs(ry2[z3]-ry2[z4]);
- s2 = klabs(rx2[z1]-rx2[z4])+klabs(ry2[z1]-ry2[z4]);
- s2 += klabs(rx2[z3]-rx2[z2])+klabs(ry2[z3]-ry2[z2]);
+ z1 = bunchWallsList[z];
+ z2 = pvWalls[z1].screenSpaceCoo[1][VEC_COL];
+ z3 = bunchWallsList[zz];
+ z4 = pvWalls[z3].screenSpaceCoo[1][VEC_COL];
+ s1 = klabs(pvWalls[z1].cameraSpaceCoo[1][VEC_X]-pvWalls[z2].cameraSpaceCoo[1][VEC_X])+klabs(pvWalls[z1].cameraSpaceCoo[1][VEC_Y]-pvWalls[z2].cameraSpaceCoo[1][VEC_Y]);
+ s1 += klabs(pvWalls[z3].cameraSpaceCoo[1][VEC_X]-pvWalls[z4].cameraSpaceCoo[1][VEC_X])+klabs(pvWalls[z3].cameraSpaceCoo[1][VEC_Y]-pvWalls[z4].cameraSpaceCoo[1][VEC_Y]);
+ s2 = klabs(pvWalls[z1].cameraSpaceCoo[1][VEC_X]-pvWalls[z4].cameraSpaceCoo[1][VEC_X])+klabs(pvWalls[z1].cameraSpaceCoo[1][VEC_Y]-pvWalls[z4].cameraSpaceCoo[1][VEC_Y]);
+ s2 += klabs(pvWalls[z3].cameraSpaceCoo[1][VEC_X]-pvWalls[z2].cameraSpaceCoo[1][VEC_X])+klabs(pvWalls[z3].cameraSpaceCoo[1][VEC_Y]-pvWalls[z2].cameraSpaceCoo[1][VEC_Y]);
if (s2 < s1)
{
- t = xb2[p2[z]];
- xb2[p2[z]] = xb2[p2[zz]];
- xb2[p2[zz]] = t;
+ t = pvWalls[bunchWallsList[z]].screenSpaceCoo[1][VEC_COL];
+ pvWalls[bunchWallsList[z]].screenSpaceCoo[1][VEC_COL] = pvWalls[bunchWallsList[zz]].screenSpaceCoo[1][VEC_COL];
+ pvWalls[bunchWallsList[zz]].screenSpaceCoo[1][VEC_COL] = t;
}
}
@@ -8505,38 +8590,38 @@
splitcnt = 0;
do
{
- s2 = ry2[z]-cy2;
+ s2 = pvWalls[z].cameraSpaceCoo[1][VEC_Y]-cy2;
do
{
- zz = xb2[z];
- xb2[z] = -1;
+ zz = pvWalls[z].screenSpaceCoo[1][VEC_COL];
+ pvWalls[z].screenSpaceCoo[1][VEC_COL] = -1;
s1 = s2;
- s2 = ry2[zz]-cy2;
+ s2 = pvWalls[zz].cameraSpaceCoo[1][VEC_Y]-cy2;
if (s1 < 0)
{
- rx1[npoints] = rx2[z];
- ry1[npoints] = ry2[z];
- xb1[npoints] = npoints+1;
+ pvWalls[npoints].cameraSpaceCoo[0][VEC_X] = pvWalls[z].cameraSpaceCoo[1][VEC_X];
+ pvWalls[npoints].cameraSpaceCoo[0][VEC_Y] = pvWalls[z].cameraSpaceCoo[1][VEC_Y];
+ pvWalls[npoints].screenSpaceCoo[0][VEC_COL] = npoints+1;
npoints++;
}
if ((s1^s2) < 0)
{
- rx1[npoints] = rx2[z]+scale(rx2[zz]-rx2[z],s1,s1-s2);
- ry1[npoints] = ry2[z]+scale(ry2[zz]-ry2[z],s1,s1-s2);
- if (s1 < 0) p2[splitcnt++] = npoints;
- xb1[npoints] = npoints+1;
+ pvWalls[npoints].cameraSpaceCoo[0][VEC_X] = pvWalls[z].cameraSpaceCoo[1][VEC_X]+scale(pvWalls[zz].cameraSpaceCoo[1][VEC_X]-pvWalls[z].cameraSpaceCoo[1][VEC_X],s1,s1-s2);
+ pvWalls[npoints].cameraSpaceCoo[0][VEC_Y] = pvWalls[z].cameraSpaceCoo[1][VEC_Y]+scale(pvWalls[zz].cameraSpaceCoo[1][VEC_Y]-pvWalls[z].cameraSpaceCoo[1][VEC_Y],s1,s1-s2);
+ if (s1 < 0) bunchWallsList[splitcnt++] = npoints;
+ pvWalls[npoints].screenSpaceCoo[0][VEC_COL] = npoints+1;
npoints++;
}
z = zz;
- } while (xb2[z] >= 0);
+ } while (pvWalls[z].screenSpaceCoo[1][VEC_COL] >= 0);
if (npoints >= start2+3)
- xb1[npoints-1] = start2, start2 = npoints;
+ pvWalls[npoints-1].screenSpaceCoo[0][VEC_COL] = start2, start2 = npoints;
else
npoints = start2;
z = 1;
- while ((z < npoints2) && (xb2[z] < 0)) z++;
+ while ((z < npoints2) && (pvWalls[z].screenSpaceCoo[1][VEC_COL] < 0)) z++;
} while (z < npoints2);
if (npoints <= 2) return(0);
@@ -8543,19 +8628,19 @@
for(z=1; z<splitcnt; z++)
for(zz=0; zz<z; zz++)
{
- z1 = p2[z];
- z2 = xb1[z1];
- z3 = p2[zz];
- z4 = xb1[z3];
- s1 = klabs(rx1[z1]-rx1[z2])+klabs(ry1[z1]-ry1[z2]);
- s1 += klabs(rx1[z3]-rx1[z4])+klabs(ry1[z3]-ry1[z4]);
- s2 = klabs(rx1[z1]-rx1[z4])+klabs(ry1[z1]-ry1[z4]);
- s2 += klabs(rx1[z3]-rx1[z2])+klabs(ry1[z3]-ry1[z2]);
+ z1 = bunchWallsList[z];
+ z2 = pvWalls[z1].screenSpaceCoo[0][VEC_COL];
+ z3 = bunchWallsList[zz];
+ z4 = pvWalls[z3].screenSpaceCoo[0][VEC_COL];
+ s1 = klabs(pvWalls[z1].cameraSpaceCoo[0][VEC_X]-pvWalls[z2].cameraSpaceCoo[0][VEC_X])+klabs(pvWalls[z1].cameraSpaceCoo[0][VEC_Y]-pvWalls[z2].cameraSpaceCoo[0][VEC_Y]);
+ s1 += klabs(pvWalls[z3].cameraSpaceCoo[0][VEC_X]-pvWalls[z4].cameraSpaceCoo[0][VEC_X])+klabs(pvWalls[z3].cameraSpaceCoo[0][VEC_Y]-pvWalls[z4].cameraSpaceCoo[0][VEC_Y]);
+ s2 = klabs(pvWalls[z1].cameraSpaceCoo[0][VEC_X]-pvWalls[z4].cameraSpaceCoo[0][VEC_X])+klabs(pvWalls[z1].cameraSpaceCoo[0][VEC_Y]-pvWalls[z4].cameraSpaceCoo[0][VEC_Y]);
+ s2 += klabs(pvWalls[z3].cameraSpaceCoo[0][VEC_X]-pvWalls[z2].cameraSpaceCoo[0][VEC_X])+klabs(pvWalls[z3].cameraSpaceCoo[0][VEC_Y]-pvWalls[z2].cameraSpaceCoo[0][VEC_Y]);
if (s2 < s1)
{
- t = xb1[p2[z]];
- xb1[p2[z]] = xb1[p2[zz]];
- xb1[p2[zz]] = t;
+ t = pvWalls[bunchWallsList[z]].screenSpaceCoo[0][VEC_COL];
+ pvWalls[bunchWallsList[z]].screenSpaceCoo[0][VEC_COL] = pvWalls[bunchWallsList[zz]].screenSpaceCoo[0][VEC_COL];
+ pvWalls[bunchWallsList[zz]].screenSpaceCoo[0][VEC_COL] = t;
}
}
}
@@ -8606,9 +8691,9 @@
x = dmulscale16(ox,xvect,-oy,yvect) + (xdim<<11);
y = dmulscale16(oy,xvect2,ox,yvect2) + (ydim<<11);
i |= getclipmask(x-cx1,cx2-x,y-cy1,cy2-y);
- rx1[npoints] = x;
- ry1[npoints] = y;
- xb1[npoints] = wal->point2 - startwall;
+ pvWalls[npoints].cameraSpaceCoo[0][VEC_X] = x;
+ pvWalls[npoints].cameraSpaceCoo[0][VEC_Y] = y;
+ pvWalls[npoints].screenSpaceCoo[0][VEC_COL] = wal->point2 - startwall;
npoints++;
}
@@ -8615,8 +8700,8 @@
if ((i&0xf0) != 0xf0)
continue;
- bakx1 = rx1[0];
- baky1 = mulscale16(ry1[0]-(ydim<<11),xyaspect)+(ydim<<11);
+ bakx1 = pvWalls[0].cameraSpaceCoo[0][VEC_X];
+ baky1 = mulscale16(pvWalls[0].cameraSpaceCoo[0][VEC_Y]-(ydim<<11),xyaspect)+(ydim<<11);
if (i&0x0f)
{
npoints = clippoly(npoints,i);
@@ -8777,10 +8862,10 @@
y3 = y2+k;
y4 = y1+k;
- xb1[0] = 1;
- xb1[1] = 2;
- xb1[2] = 3;
- xb1[3] = 0;
+ pvWalls[0].screenSpaceCoo[0][VEC_COL] = 1;
+ pvWalls[1].screenSpaceCoo[0][VEC_COL] = 2;
+ pvWalls[2].screenSpaceCoo[0][VEC_COL] = 3;
+ pvWalls[3].screenSpaceCoo[0][VEC_COL] = 0;
npoints = 4;
i = 0;
@@ -8790,8 +8875,8 @@
x = dmulscale16(ox,xvect,-oy,yvect) + (xdim<<11);
y = dmulscale16(oy,xvect2,ox,yvect2) + (ydim<<11);
i |= getclipmask(x-cx1,cx2-x,y-cy1,cy2-y);
- rx1[0] = x;
- ry1[0] = y;
+ pvWalls[0].cameraSpaceCoo[0][VEC_X] = x;
+ pvWalls[0].cameraSpaceCoo[0][VEC_Y] = y;
ox = x2 - dax;
oy = y2 - day;
@@ -8798,8 +8883,8 @@
x = dmulscale16(ox,xvect,-oy,yvect) + (xdim<<11);
y = dmulscale16(oy,xvect2,ox,yvect2) + (ydim<<11);
i |= getclipmask(x-cx1,cx2-x,y-cy1,cy2-y);
- rx1[1] = x;
- ry1[1] = y;
+ pvWalls[1].cameraSpaceCoo[0][VEC_X] = x;
+ pvWalls[1].cameraSpaceCoo[0][VEC_Y] = y;
ox = x3 - dax;
oy = y3 - day;
@@ -8806,18 +8891,18 @@
x = dmulscale16(ox,xvect,-oy,yvect) + (xdim<<11);
y = dmulscale16(oy,xvect2,ox,yvect2) + (ydim<<11);
i |= getclipmask(x-cx1,cx2-x,y-cy1,cy2-y);
- rx1[2] = x;
- ry1[2] = y;
+ pvWalls[2].cameraSpaceCoo[0][VEC_X] = x;
+ pvWalls[2].cameraSpaceCoo[0][VEC_Y] = y;
- x = rx1[0]+rx1[2]-rx1[1];
- y = ry1[0]+ry1[2]-ry1[1];
+ x = pvWalls[0].cameraSpaceCoo[0][VEC_X]+pvWalls[2].cameraSpaceCoo[0][VEC_X]-pvWalls[1].cameraSpaceCoo[0][VEC_X];
+ y = pvWalls[3].cameraSpaceCoo[0][VEC_Y]+pvWalls[2].cameraSpaceCoo[0][VEC_Y]-pvWalls[1].cameraSpaceCoo[0][VEC_Y];
i |= getclipmask(x-cx1,cx2-x,y-cy1,cy2-y);
- rx1[3] = x;
- ry1[3] = y;
+ pvWalls[3].cameraSpaceCoo[0][VEC_X] = x;
+ pvWalls[3].cameraSpaceCoo[0][VEC_Y] = y;
if ((i&0xf0) != 0xf0) continue;
- bakx1 = rx1[0];
- baky1 = mulscale16(ry1[0]-(ydim<<11),xyaspect)+(ydim<<11);
+ bakx1 = pvWalls[0].cameraSpaceCoo[0][VEC_X];
+ baky1 = mulscale16(pvWalls[0].cameraSpaceCoo[0][VEC_Y]-(ydim<<11),xyaspect)+(ydim<<11);
if (i&0x0f)
{
npoints = clippoly(npoints,i);
--- a/Engine/src/filesystem.c
+++ b/Engine/src/filesystem.c
@@ -15,140 +15,154 @@
char game_dir[512];
-uint8_t toupperlookup[256] =
-{
- 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,
- 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,
- 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,
- 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,
- 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,
- 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f,
- 0x60,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,
- 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x7b,0x7c,0x7d,0x7e,0x7f,
- 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,
- 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,
- 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,
- 0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,
- 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,
- 0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf,
- 0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef,
- 0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff,
-};
-
-int32_t numgroupfiles = 0; // number of GRP files actually used.
-int32_t gnumfiles[MAXGROUPFILES]; // number of files on grp
-int32_t groupfil[MAXGROUPFILES] = {-1,-1,-1,-1}; // grp file handles
-int32_t groupfilpos[MAXGROUPFILES];
-uint8_t *gfilelist[MAXGROUPFILES]; // name list + size list of all the files in grp
-int32_t *gfileoffs[MAXGROUPFILES]; // offset of the files
-uint8_t *groupfil_memory[MAXGROUPFILES]; // addresses of raw GRP files in memory
+//The multiplayer module in game.dll needs direct access to the crc32 (sic).
int32_t groupefil_crc32[MAXGROUPFILES];
-uint8_t filegrp[MAXOPENFILES];
-int32_t filepos[MAXOPENFILES];
-int32_t filehan[MAXOPENFILES] =
-{
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
- -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-};
+// A typical GRP index entry:
+// - 12 bytes for filename
+// - 4 for filesize
+typedef uint8_t grpIndexEntry_t[16];
+typedef struct grpArchive_s{
+
+ int32_t numFiles ;//Number of files in the archive.
+ grpIndexEntry_t *gfilelist ;//Array containing the filenames.
+ int32_t *fileOffsets ;//Array containing the file offsets.
+ int32_t *filesizes ;//Array containing the file offsets.
+ int fileDescriptor ;//The fd used for open,read operations.
+ uint32_t crc32 ;//Hash to recognize GRP: Duke Shareware, Duke plutonimum etc...
+
+} grpArchive_t;
+//All GRP opened are in this structure
+typedef struct grpSet_s{
+ grpArchive_t archives[MAXGROUPFILES];
+ int32_t num;
+} grpSet_t;
+
+// Marking it static gurantee not only invisility outside module
+// but also that the content will be set to 0.
+static grpSet_t grpSet;
+
+
+
int32_t initgroupfile(const char *filename)
{
- uint8_t buf[16];
- int32_t i, j, k;
+ uint8_t buf[16] ;
+ int32_t i, j, k ;
+ grpArchive_t* archive ;
+ uint8_t crcBuffer[ 1 << 20] ;
+
printf("Loading %s ...\n", filename);
- if (numgroupfiles >= MAXGROUPFILES) return(-1);
+ if (grpSet.num == MAXGROUPFILES){
+ printf("Error: Unable to open an extra GRP archive <= No more slot available.\n");
+ return(-1);
+ }
- groupfil_memory[numgroupfiles] = NULL; // addresses of raw GRP files in memory
- groupefil_crc32[numgroupfiles] = 0;
+ archive = &grpSet.archives[grpSet.num];
- groupfil[numgroupfiles] = open(filename,O_BINARY|O_RDWR,S_IREAD);
- if (groupfil[numgroupfiles] >= 0)
- {
- groupfilpos[numgroupfiles] = 0;
- read(groupfil[numgroupfiles],buf,16);
- if ((buf[0] != 'K') || (buf[1] != 'e') || (buf[2] != 'n') ||
- (buf[3] != 'S') || (buf[4] != 'i') || (buf[5] != 'l') ||
- (buf[6] != 'v') || (buf[7] != 'e') || (buf[8] != 'r') ||
- (buf[9] != 'm') || (buf[10] != 'a') || (buf[11] != 'n'))
- {
- close(groupfil[numgroupfiles]);
- groupfil[numgroupfiles] = -1;
- return(-1);
- }
+ //Init the slot
+ memset(archive, 0, sizeof(grpArchive_t));
+
+ //groupfil_memory[numgroupfiles] = NULL; // addresses of raw GRP files in memory
+ //groupefil_crc32[numgroupfiles] = 0;
+
+ archive->fileDescriptor = open(filename,O_BINARY|O_RDWR,S_IREAD);
+
+ if (archive->fileDescriptor < 0){
+ printf("Error: Unable to open file %s.\n",filename);
+ getchar();
+ exit(0);
+ }
+
+
+ read(archive->fileDescriptor,buf,16);
+
+ //FCS : The ".grp" file format is just a collection of a lot of files stored into 1 big one.
+ //KS doc: I tried to make the format as simple as possible: The first 12 bytes contains my name,
+ //"KenSilverman". The next 4 bytes is the number of files that were compacted into the
+ //group file. Then for each file, there is a 16 byte structure, where the first 12
+ //bytes are the filename, and the last 4 bytes are the file's size. The rest of the
+ //group file is just the raw data packed one after the other in the same order as the list
+ //of files. - ken
+
+ // Check the magic number (12 bytes header).
+ if ((buf[0] != 'K') || (buf[1] != 'e') || (buf[2] != 'n') ||
+ (buf[3] != 'S') || (buf[4] != 'i') || (buf[5] != 'l') ||
+ (buf[6] != 'v') || (buf[7] != 'e') || (buf[8] != 'r') ||
+ (buf[9] != 'm') || (buf[10] != 'a') || (buf[11] != 'n')){
+ printf("Error: File %s is not a GRP archive.\n",filename);
+ return(-1);
+ }
+
+
+
+
+ // The next 4 bytes of the header feature the number of files in the GRP archive.
+ archive->numFiles = BUILDSWAP_INTEL32(*((int32_t *)&buf[12]));
+
+
+ archive->gfilelist = kmalloc(archive->numFiles * sizeof(grpIndexEntry_t));
+ archive->fileOffsets = kmalloc(archive->numFiles * sizeof(int32_t));
+ archive->filesizes = kmalloc(archive->numFiles * sizeof(int32_t));
+
+ // Load the full index 16 bytes per file (12bytes for name + 4 bytes for the size).
+ read(archive->fileDescriptor,archive->gfilelist, archive->numFiles * 16);
+
+ //Initialize all file offset and pointers.
+ j = 12 + 4 + archive->numFiles * sizeof(grpIndexEntry_t);
+ for(i=0;i<archive->numFiles;i++){
- //FCS: The ".grp" file format is just a collection of a lot of files stored into 1 big one.
- //I tried to make the format as simple as possible: The first 12 bytes contains my name,
- //"KenSilverman". The next 4 bytes is the number of files that were compacted into the
- //group file. Then for each file, there is a 16 byte structure, where the first 12
- //bytes are the filename, and the last 4 bytes are the file's size. The rest of the
- //group file is just the raw data packed one after the other in the same order as the list
- //of files. - ken
+ k = BUILDSWAP_INTEL32(*((int32_t *)&archive->gfilelist[i][12])); // get size
- gnumfiles[numgroupfiles] = BUILDSWAP_INTEL32(*((int32_t *)&buf[12]));
-
- if ((gfilelist[numgroupfiles] = (uint8_t *)kmalloc(gnumfiles[numgroupfiles]<<4)) == 0)
- { Error(EXIT_FAILURE, "Not enough memory for file grouping system\n"); }
- if ((gfileoffs[numgroupfiles] = (int32_t *)kmalloc((gnumfiles[numgroupfiles]+1)<<2)) == 0)
- { Error(EXIT_FAILURE, "Not enough memory for file grouping system\n"); }
-
- // load index (name+size)
- read(groupfil[numgroupfiles],gfilelist[numgroupfiles],gnumfiles[numgroupfiles]<<4);
-
- j = 0;
- for(i=0;i<gnumfiles[numgroupfiles];i++)
- {
- k = BUILDSWAP_INTEL32(*((int32_t *)&gfilelist[numgroupfiles][(i<<4)+12])); // get size
- gfilelist[numgroupfiles][(i<<4)+12] = 0;
- gfileoffs[numgroupfiles][i] = j; // absolute offset list of all files. 0 for 1st file
- j += k;
- }
- gfileoffs[numgroupfiles][gnumfiles[numgroupfiles]] = j;
- }
- else
- {
- printf("Unable to find GRP file %s.\n",filename);
- //Let user see the message
- getchar();
- exit(0);
+ // Now that the filesize has been read, we can replace it with '0' and hence have a
+ // valid, null terminated character string that will be usable.
+ archive->gfilelist[i][12] = '\0';
+ archive->filesizes[i] = k;
+ archive->fileOffsets[i] = j; // absolute offset list of all files.
+ j += k;
}
+ //archive->fileOffsets[archive->numFiles-1] = j;
+
- // Compute CRC32 of thw whole grp and implicitely caches the GRP in memory through windows
- lseek(groupfil[numgroupfiles], 0, SEEK_SET);
+ // Compute CRC32 of the whole grp and implicitely caches the GRP in memory through windows caching service.
+ // Rewind the fileDescriptor
+ lseek(archive->fileDescriptor, 0, SEEK_SET);
- i = 1000000; // FIX_00086: grp loaded by smaller sucessive chunks to avoid overloading low ram computers
- groupfil_memory[numgroupfiles] = malloc(i);
- while((j=read(groupfil[numgroupfiles], groupfil_memory[numgroupfiles], i)))
- {
- groupefil_crc32[numgroupfiles] = crc32_update((uint8_t *)groupfil_memory[numgroupfiles], j, groupefil_crc32[numgroupfiles]);
+ //i = 1000000;
+ //groupfil_memory[numgroupfiles] = malloc(i);
+
+ //Load the full GRP in RAM.
+ while((j=read(archive->fileDescriptor, crcBuffer, sizeof(crcBuffer)))){
+ archive->crc32 = crc32_update(crcBuffer,j,archive->crc32);
}
- free(groupfil_memory[numgroupfiles]);
- groupfil_memory[numgroupfiles] = 0;
+ // The game layer seems to absolutely need to access an array int[4] groupefil_crc32
+ // so we need to store the crc32 in there too.
+ groupefil_crc32[grpSet.num] = archive->crc32;
- numgroupfiles++;
- return(groupfil[numgroupfiles-1]);
+ //free(groupfil_memory[numgroupfiles]);
+ //groupfil_memory[numgroupfiles] = 0;
+ grpSet.num++;
+
+ return(grpSet.num-1);
+
}
void uninitgroupfile(void)
{
- int32_t i;
+ int i;
- for(i=numgroupfiles-1;i>=0;i--)
- if (groupfil[i] != -1)
- {
- kfree(gfilelist[i]);
- kfree(gfileoffs[i]);
- close(groupfil[i]);
- groupfil[i] = -1;
- }
+ for( i=0 ; i < grpSet.num ;i++){
+ free(grpSet.archives[i].gfilelist);
+ free(grpSet.archives[i].fileOffsets);
+ free(grpSet.archives[i].filesizes);
+ memset(&grpSet.archives[i], 0, sizeof(grpArchive_t));
+ }
}
@@ -233,93 +247,112 @@
return (crc);
}
-int32_t kopen4load(const char *filename, int readfromGRP)
-{ // FIX_00072: all files are now 1st searched in Duke's root folder and then in the GRP.
- int32_t i, j, k, fil, newhandle;
- uint8_t bad;
- uint8_t *gfileptr;
+// The engine can open files transparently on the filesystem or on the GRPsystem
+enum fileType_e{ SYSTEM_FILE, GRP_FILE} ;
+
+//An entry in the array tracking open files
+typedef struct openFile_s{
+ enum fileType_e type ;
+ int fd ; //Either the fileDescriptor or the fileIndex in a GRP depending on the type.
+ int cursor ; //lseek cursor
+ int grpID ; //GRP id
+ int used ; //Marker 1=used
+} openFile_t;
+
+
+#define MAXOPENFILES 64
+static openFile_t openFiles[MAXOPENFILES];
+
+int32_t kopen4load(const char *filename, int openOnlyFromGRP){
+ int32_t i, k;
+ int32_t newhandle;
+
+ grpArchive_t* archive;
+
+ //Search a free slot
newhandle = MAXOPENFILES-1;
- while (filehan[newhandle] != -1)
- {
+ while (openFiles[newhandle].used && newhandle >= 0)
newhandle--;
- if (newhandle < 0)
- {
- Error(EXIT_FAILURE, "Too Many files open!\n");
- }
- }
+
+
+ if (newhandle < 0)
+ Error(EXIT_FAILURE, "Too Many files open!\n");
- if(!readfromGRP)
- if ((fil = open(filename,O_BINARY|O_RDONLY)) != -1)
- {
- filegrp[newhandle] = 255;
- filehan[newhandle] = fil;
- filepos[newhandle] = 0;
- printf("Reading external %s \n", filename);
- return(newhandle);
- }
-
- for(k=numgroupfiles-1;k>=0;k--)
- {
- if (groupfil[k] != -1)
- {
- for(i=gnumfiles[k]-1;i>=0;i--)
- {
- gfileptr = (uint8_t *)&gfilelist[k][i<<4];
-
- bad = 0;
- for(j=0;j<13;j++)
- {
- if (!filename[j]) break;
- if (toupperlookup[(int) filename[j]] != toupperlookup[(int) gfileptr[j]])
- { bad = 1; break; }
- }
- if (bad) continue;
-
- filegrp[newhandle] = (uint8_t ) k;
- filehan[newhandle] = i;
- filepos[newhandle] = 0;
- return(newhandle);
- }
- }
+
+ //Try to look in the filesystem first. In this case fd = filedescriptor.
+ if(!openOnlyFromGRP){
+
+ openFiles[newhandle].fd = open(filename,O_BINARY|O_RDONLY);
+
+ if (openFiles[newhandle].fd != -1){
+ openFiles[newhandle].type = SYSTEM_FILE;
+ openFiles[newhandle].cursor = 0;
+ openFiles[newhandle].used = 1;
+ return(newhandle);
+ }
+ }
+
+ //Try to look in the GRP archives. In this case fd = index of the file in the GRP.
+ for(k=grpSet.num-1;k>=0;k--)
+ {
+ archive = &grpSet.archives[k];
+
+ for(i=archive->numFiles-1;i>=0;i--){
+
+ if (!strncasecmp((char*)archive->gfilelist[i],filename,12)){
+
+ openFiles[newhandle].type = GRP_FILE;
+ openFiles[newhandle].used = 1;
+ openFiles[newhandle].cursor = 0;
+ openFiles[newhandle].fd = i;
+ openFiles[newhandle].grpID = k;
+ return(newhandle);
+ }
+ }
}
+
return(-1);
}
-int32_t kread(int32_t handle, void *buffer, int32_t leng)
-{
- int32_t i, filenum, groupnum;
+int32_t kread(int32_t handle, void *buffer, int32_t leng){
- filenum = filehan[handle];
- groupnum = filegrp[handle];
+ openFile_t * openFile ;
+ grpArchive_t * archive ;
- if (groupnum == 255) // Reading external
- {
- return(read(filenum,buffer,leng));
- }
+ openFile = &openFiles[handle];
- if (groupfil[groupnum] != -1)
- {
- i = gfileoffs[groupnum][filenum]+filepos[handle];
- if (i != groupfilpos[groupnum])
- {
- lseek(groupfil[groupnum],i+((gnumfiles[groupnum]+1)<<4),SEEK_SET);
- groupfilpos[groupnum] = i;
- }
- leng = min(leng,(gfileoffs[groupnum][filenum+1]-gfileoffs[groupnum][filenum])-filepos[handle]);
- leng = read(groupfil[groupnum],buffer,leng);
- filepos[handle] += leng;
- groupfilpos[groupnum] += leng;
- return(leng);
- }
+ if (!openFile->used){
+ printf("Invalide handle. Unrecoverable error.\n");
+ getchar();
+ exit(0);
+ }
- return(0);
+ //FILESYSTEM ? OS takes care of it !
+ if (openFile->type == SYSTEM_FILE){
+ return(read(openFile->fd,buffer,leng));
+ }
+ //File is actually in the GRP
+ archive = & grpSet.archives[openFile->grpID];
+
+ lseek(archive->fileDescriptor,
+ archive->fileOffsets[openFile->fd] + openFile->cursor,
+ SEEK_SET);
+
+ //Adjust leng so we cannot read more than filesystem-cursor location.
+ leng = min(leng,archive->filesizes[openFile->fd]-openFile->cursor);
+
+ leng = read(archive->fileDescriptor,buffer,leng);
+
+ openFile->cursor += leng;
+
+ return leng;
+
}
-int kread16(int32_t handle, short *buffer)
-{
+int kread16(int32_t handle, short *buffer){
if (kread(handle, buffer, 2) != 2)
return(0);
@@ -327,8 +360,7 @@
return(1);
}
-int kread32(int32_t handle, int32_t *buffer)
-{
+int kread32(int32_t handle, int32_t *buffer){
if (kread(handle, buffer, 4) != 4)
return(0);
@@ -336,8 +368,7 @@
return(1);
}
-int kread8(int32_t handle, uint8_t *buffer)
-{
+int kread8(int32_t handle, uint8_t *buffer){
if (kread(handle, buffer, 1) != 1)
return(0);
@@ -344,32 +375,37 @@
return(1);
}
-int32_t klseek(int32_t handle, int32_t offset, int32_t whence)
-{
- int32_t i, groupnum;
+int32_t klseek(int32_t handle, int32_t offset, int whence){
- groupnum = filegrp[handle];
+ grpArchive_t* archive;
+
+ if (!openFiles[handle].used){
+ printf("Invalide handle. Unrecoverable error.\n");
+ getchar();
+ exit(0);
+ }
- if (groupnum == 255) return((int32_t )lseek(filehan[handle],offset,whence));
- if (groupfil[groupnum] != -1)
- {
- switch(whence)
- {
- case SEEK_SET: filepos[handle] = offset; break;
- case SEEK_END: i = filehan[handle];
- filepos[handle] = (gfileoffs[groupnum][i+1]-gfileoffs[groupnum][i])+offset;
- break;
- case SEEK_CUR: filepos[handle] += offset; break;
- }
- return(filepos[handle]);
- }
- return(-1);
+ // FILESYSTEM ? OS will take care of it.
+ if (openFiles[handle].type == SYSTEM_FILE){
+ return lseek(openFiles[handle].fd,offset,whence);
+ }
+
+ archive = & grpSet.archives [ openFiles[handle].grpID ];
+
+ switch(whence){
+ case SEEK_SET: openFiles[handle].cursor = offset; break;
+ case SEEK_END: openFiles[handle].cursor = archive->filesizes[openFiles[handle].fd]; break;
+ case SEEK_CUR: openFiles[handle].cursor += offset; break;
+ }
+
+ return(openFiles[handle].cursor);
+
+
}
#ifdef __APPLE__
-int32_t filelength(int32_t fd)
-{
+int32_t filelength(int32_t fd){
struct stat stats;
fstat(fd, &stats);
return (int32_t )stats.st_size;
@@ -378,21 +414,45 @@
int32_t kfilelength(int32_t handle)
{
- int32_t i, groupnum;
+ openFile_t* openFile = &openFiles[handle];
- groupnum = filegrp[handle];
- if (groupnum == 255) return(filelength(filehan[handle]));
- i = filehan[handle];
- return(gfileoffs[groupnum][i+1]-gfileoffs[groupnum][i]);
+ if (!openFile->used){
+ printf("Invalide handle. Unrecoverable error.\n");
+ getchar();
+ exit(0);
+ }
+ if (openFile->type == SYSTEM_FILE){
+ return(filelength(openFile->fd));
+ }
+
+ else{
+ grpArchive_t* archive = &grpSet.archives[ openFile->grpID ];
+ return archive->filesizes[openFile->fd];
+ }
+
}
void kclose(int32_t handle)
{
- if (handle < 0) return;
- if (filegrp[handle] == 255) close(filehan[handle]);
- filehan[handle] = -1;
+ openFile_t* openFile = &openFiles[handle];
+ //This is a typical handle for a non existing file.
+ if (handle == -1)
+ return;
+
+ if (!openFile->used){
+ printf("Invalide handle. Unrecoverable error.\n");
+ getchar();
+ exit(0);
+ }
+
+ if (openFile->type == SYSTEM_FILE){
+ close(openFile->fd);
+ }
+
+ memset(openFile, 0, sizeof(openFile_t));
+
}
@@ -670,4 +730,7 @@
return game_dir;
}
-
+int getGRPcrc32(int grpID){
+
+ return grpSet.archives[grpID].crc32;
+}
--- a/Engine/src/filesystem.h
+++ b/Engine/src/filesystem.h
@@ -12,21 +12,23 @@
#include "stdio.h"
#include "platform.h"
+
+
#define MAXGROUPFILES 4 /* Warning: Fix groupfil if this is changed */
-#define MAXOPENFILES 64 /* Warning: Fix filehan if this is changed */
-extern int32_t groupefil_crc32[4];
+extern int32_t groupefil_crc32[MAXGROUPFILES];
+
int32_t initgroupfile(const char *filename);
void uninitgroupfile(void);
uint16_t crc16(uint8_t *data_p, uint16_t length);
uint32_t crc32_update(uint8_t *buf, uint32_t length, uint32_t crc_to_update);
-int32_t kopen4load(const char *filename, int readfromGRP);
+int32_t kopen4load(const char *filename, int openOnlyFromGRP);
int32_t kread(int32_t handle, void *buffer, int32_t leng);
int32_t kread8(int32_t handle, uint8_t *buffer);
int32_t kread16(int32_t handle, int16_t *buffer);
int32_t kread32(int32_t handle, int32_t *buffer);
-int32_t klseek(int32_t handle, int32_t offset, int32_t whence);
+int32_t klseek(int32_t handle, int32_t offset, int whence);
int32_t kfilelength(int32_t handle);
void kclose(int32_t handle);
void kdfread(void *buffer, size_t dasizeof, size_t count, int32_t fil);
@@ -33,6 +35,7 @@
void dfread(void *buffer, size_t dasizeof, size_t count, FILE *fil);
void dfwrite(void *buffer, size_t dasizeof, size_t count, FILE *fil);
+int getGRPcrc32(int grpID);
char* getGameDir(void);
void setGameDir(char* gameDir);
--- a/Engine/src/mmulti.c
+++ b/Engine/src/mmulti.c
@@ -26,7 +26,7 @@
#include "platform.h"
-#include "pragmas.h"
+#include "fixedPoint_math.h"
#define MAXPLAYERS 16
#define BAKSIZ 16384
--- a/Engine/src/mmulti_stable.cpp
+++ b/Engine/src/mmulti_stable.cpp
@@ -16,7 +16,7 @@
{
#include "platform.h"
-#include "pragmas.h"
+#include "fixedPoint_math.h"
#include "signal.h"
#include "mmulti_stable.h"
#include "filesystem.h"
--- a/Game/src/animlib.c
+++ b/Game/src/animlib.c
@@ -199,7 +199,7 @@
//****************************************************************************
void renderframe (uint16 framenumber, uint16 *pagepointer)
- {
+{
uint16 offset=0;
uint16 i;
uint16 destframe;
@@ -209,23 +209,18 @@
destframe = framenumber - anim->curlp.baseRecord;
for(i = 0; i < destframe; i++)
- {
offset += pagepointer[i];
- }
+
ppointer = (byte *)pagepointer;
ppointer+=anim->curlp.nRecords*2+offset;
if(ppointer[1])
- {
ppointer += (4 + (((uint16 *)ppointer)[1] + (((uint16 *)ppointer)[1] & 1)));
- }
else
- {
ppointer+=4;
- }
CPlayRunSkipDump (ppointer, anim->imagebuffer);
- }
+}
//****************************************************************************
--- a/Game/src/audiolib/_multivc.h
+++ b/Game/src/audiolib/_multivc.h
@@ -99,11 +99,11 @@
playbackstatus ( *GetSound )( struct VoiceNode *voice );
void ( *mix )( unsigned long position, unsigned long rate,
- const char *start, unsigned long length );
+ uint8_t *start, unsigned long length );
- char *NextBlock;
- char *LoopStart;
- char *LoopEnd;
+ uint8_t *NextBlock;
+ uint8_t *LoopStart;
+ uint8_t *LoopEnd;
unsigned LoopCount;
unsigned long LoopSize;
unsigned long BlockLength;
@@ -111,7 +111,7 @@
unsigned long PitchScale;
unsigned long FixedPointBufferSize;
- char *sound;
+ uint8_t *sound;
unsigned long length;
unsigned long SamplingRate;
unsigned long RateScale;
--- a/Game/src/audiolib/fx_man.c
+++ b/Game/src/audiolib/fx_man.c
@@ -622,7 +622,7 @@
int FX_PlayVOC
(
- char *ptr,
+ uint8_t *ptr,
int pitchoffset,
int vol,
int left,
@@ -688,7 +688,7 @@
int FX_PlayWAV
(
- char *ptr,
+ uint8_t *ptr,
int32_t pitchoffset,
int32_t vol,
int32_t left,
--- a/Game/src/audiolib/fx_man.h
+++ b/Game/src/audiolib/fx_man.h
@@ -106,12 +106,12 @@
int FX_SetPitch( int handle, int pitchoffset );
int FX_SetFrequency( int handle, int frequency );
-int FX_PlayVOC( char *ptr, int pitchoffset, int vol, int left, int right,
+int FX_PlayVOC( uint8_t *ptr, int pitchoffset, int vol, int left, int right,
int priority, uint32_t callbackval );
int FX_PlayLoopedVOC( uint8_t *ptr, int32_t loopstart, int32_t loopend,
int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t priority,
uint32_t callbackval );
-int FX_PlayWAV( char *ptr, int pitchoffset, int vol, int left, int right,
+int FX_PlayWAV( uint8_t *ptr, int pitchoffset, int vol, int left, int right,
int priority, uint32_t callbackval );
int FX_PlayLoopedWAV( uint8_t *ptr, int32_t loopstart, int32_t loopend,
int32_t pitchoffset, int32_t vol, int32_t left, int32_t right, int32_t priority,
--- a/Game/src/audiolib/multivoc.c
+++ b/Game/src/audiolib/multivoc.c
@@ -288,7 +288,7 @@
static void MV_Mix( VoiceNode *voice )
{
- char *start;
+ uint8_t *start;
int length;
long voclength;
unsigned long position;
@@ -538,7 +538,7 @@
unsigned char *ptr;
int blocktype;
int lastblocktype;
- unsigned long blocklength;
+ uint32_t blocklength;
unsigned long samplespeed;
unsigned int tc;
int packtype;
@@ -2163,8 +2163,8 @@
(
uint8_t *ptr,
unsigned long length,
- char *loopstart,
- char *loopend,
+ uint8_t *loopstart,
+ uint8_t *loopend,
unsigned rate,
int pitchoffset,
int vol,
@@ -2230,7 +2230,7 @@
int MV_PlayWAV
(
- char *ptr,
+ uint8_t *ptr,
int pitchoffset,
int vol,
int left,
@@ -2499,7 +2499,7 @@
int MV_PlayVOC
(
- char *ptr,
+ uint8_t *ptr,
int pitchoffset,
int vol,
int left,
@@ -2549,7 +2549,7 @@
}
// Make sure it's a valid VOC file.
- status = strncmp( ptr, "Creative Voice File", 19 );
+ status = strncmp( (char*)ptr, "Creative Voice File", 19 );
if ( status != 0 )
{
MV_SetErrorCode( MV_InvalidVOCFile );
--- a/Game/src/audiolib/multivoc.h
+++ b/Game/src/audiolib/multivoc.h
@@ -95,10 +95,10 @@
unsigned rate, int pitchoffset, int vol, int left,
int right, int priority, unsigned long callbackval );
int MV_PlayLoopedRaw( uint8_t *ptr, unsigned long length,
- char *loopstart, char *loopend, unsigned rate, int pitchoffset,
+ uint8_t *loopstart, uint8_t *loopend, unsigned rate, int pitchoffset,
int vol, int left, int right, int priority,
unsigned long callbackval );
-int MV_PlayWAV( char *ptr, int pitchoffset, int vol, int left,
+int MV_PlayWAV( uint8_t *ptr, int pitchoffset, int vol, int left,
int right, int priority, unsigned long callbackval );
int MV_PlayWAV3D( uint8_t *ptr, int pitchoffset, int angle, int distance,
int priority, unsigned long callbackval );
@@ -107,7 +107,7 @@
unsigned long callbackval );
int MV_PlayVOC3D( uint8_t *ptr, int pitchoffset, int angle, int distance,
int priority, unsigned long callbackval );
-int MV_PlayVOC( char *ptr, int pitchoffset, int vol, int left, int right,
+int MV_PlayVOC( uint8_t * ptr, int pitchoffset, int vol, int left, int right,
int priority, unsigned long callbackval );
int MV_PlayLoopedVOC( uint8_t *ptr, long loopstart, long loopend,
int pitchoffset, int vol, int left, int right, int priority,
--- a/Game/src/duke3d.h
+++ b/Game/src/duke3d.h
@@ -121,9 +121,9 @@
// implies conVersion == 14 or conVersion == 15
#define PLUTOPAK (!VOLUMEONE && !VOLUMEALL)
-#define VOLUMEONE (groupefil_crc32[0]==CRC_BASE_GRP_SHAREWARE_13)
+#define VOLUMEONE (getGRPcrc32(0)==CRC_BASE_GRP_SHAREWARE_13)
// VOLUMEALL = 1.3d full
-#define VOLUMEALL (groupefil_crc32[0]==CRC_BASE_GRP_FULL_13 || conVersion == 13 && groupefil_crc32[0]!=CRC_BASE_GRP_SHAREWARE_13 && groupefil_crc32[0]!=CRC_BASE_GRP_PLUTONIUM_14 && groupefil_crc32[0]!=CRC_BASE_GRP_ATOMIC_15)
+#define VOLUMEALL (getGRPcrc32(0)==CRC_BASE_GRP_FULL_13 || conVersion == 13 && getGRPcrc32(0)!=CRC_BASE_GRP_SHAREWARE_13 && getGRPcrc32(0)!=CRC_BASE_GRP_PLUTONIUM_14 && getGRPcrc32(0)!=CRC_BASE_GRP_ATOMIC_15)
#define SCREENSHOTPATH "screenshots"
--- a/Game/src/gamedef.c
+++ b/Game/src/gamedef.c
@@ -1588,7 +1588,7 @@
*script = (int32_t) scriptptr;
if(warning|error)
- printf("Found %hhd warning(s), %c error(s).\n",warning,error);
+ printf("Found %hhd warning(s), '%c' error(s).\n",warning,error);
if(error)
{
@@ -1608,8 +1608,8 @@
// FIX_00022: Automatically recognize the shareware grp (v1.3) + full version (1.3d) +
// atomic (1.4/1.5 grp) and the con files version (either 1.3 or 1.4) (JonoF's idea)
- if(conVersion != 13 && (groupefil_crc32[0]==CRC_BASE_GRP_SHAREWARE_13 ||
- groupefil_crc32[0]==CRC_BASE_GRP_FULL_13) && !groupefil_crc32[1])
+ if(conVersion != 13 && (getGRPcrc32(0)==CRC_BASE_GRP_SHAREWARE_13 ||
+ getGRPcrc32(0)==CRC_BASE_GRP_FULL_13) && !getGRPcrc32(1))
{
printf( "\nYou are trying to use a v1.3 Shareware/Full *.GRP with v1.4 or v1.5\n"
"external *.CON files. You may run in troubles by doing so and/or get\n"
@@ -1627,7 +1627,7 @@
loadefs(filenam, mptr, 1); // force GRP con files
}
}
- else if(conVersion != 15 && groupefil_crc32[0]==CRC_BASE_GRP_ATOMIC_15 && !groupefil_crc32[1])
+ else if(conVersion != 15 && getGRPcrc32(0)==CRC_BASE_GRP_ATOMIC_15 && !getGRPcrc32(1))
{
printf( "\nYou are trying to use a v1.5 ATOMIC *.GRP with v1.4 or v1.3\n"
"external *.CON files. You may run in troubles by doing so and/or get\n"
@@ -1643,7 +1643,7 @@
{
loadefs(filenam, mptr, 1); // force GRP con files
}
- }else if(conVersion != 14 && groupefil_crc32[0]==CRC_BASE_GRP_PLUTONIUM_14 && !groupefil_crc32[1])
+ }else if(conVersion != 14 && getGRPcrc32(0)==CRC_BASE_GRP_PLUTONIUM_14 && !getGRPcrc32(1))
{
printf( "\nYou are trying to use a v1.4 PLUTONIUM *.GRP with v1.3 or v1.5\n"
"external *.CON files. You may run in troubles by doing so and/or get\n"