📄 l_bsp_sin.c
字号:
memset(sin_dbrushsidetextured, false, SIN_MAX_MAP_BRUSHSIDES);
//go over all the brushes
for (i = 0; i < sin_numbrushes; i++)
{
brush = &sin_dbrushes[i];
//hint brushes are not textured
if (Sin_HintSkipBrush(brush)) continue;
//go over all the sides of the brush
for (j = 0; j < brush->numsides; j++)
{
brushside = &sin_dbrushsides[brush->firstside + j];
//
w = Sin_BrushSideWinding(brush, brushside);
if (!w)
{
sin_dbrushsidetextured[brush->firstside + j] = true;
continue;
} //end if
else
{
//RemoveEqualPoints(w, 0.2);
if (WindingIsTiny(w))
{
FreeWinding(w);
sin_dbrushsidetextured[brush->firstside + j] = true;
continue;
} //end if
else
{
we = WindingError(w);
if (we == WE_NOTENOUGHPOINTS
|| we == WE_SMALLAREA
|| we == WE_POINTBOGUSRANGE
// || we == WE_NONCONVEX
)
{
FreeWinding(w);
sin_dbrushsidetextured[brush->firstside + j] = true;
continue;
} //end if
} //end else
} //end else
if (WindingArea(w) < 20)
{
sin_dbrushsidetextured[brush->firstside + j] = true;
} //end if
//find a face for texturing this brush
for (k = 0; k < sin_numfaces; k++)
{
face = &sin_dfaces[k];
//if the face is in the same plane as the brush side
if ((face->planenum&~1) != (brushside->planenum&~1)) continue;
//if the face is partly or totally on the brush side
if (Sin_FaceOnWinding(face, w))
{
brushside->texinfo = face->texinfo;
sin_dbrushsidetextured[brush->firstside + j] = true;
break;
} //end if
} //end for
FreeWinding(w);
} //end for
} //end for
} //end of the function Sin_FixTextureReferences*/
/*
===============
CompressVis
===============
*/
int Sin_CompressVis (byte *vis, byte *dest)
{
int j;
int rep;
int visrow;
byte *dest_p;
dest_p = dest;
// visrow = (r_numvisleafs + 7)>>3;
visrow = (sin_dvis->numclusters + 7)>>3;
for (j=0 ; j<visrow ; j++)
{
*dest_p++ = vis[j];
if (vis[j])
continue;
rep = 1;
for ( j++; j<visrow ; j++)
if (vis[j] || rep == 255)
break;
else
rep++;
*dest_p++ = rep;
j--;
}
return dest_p - dest;
} //end of the function Sin_CompressVis
/*
===================
DecompressVis
===================
*/
void Sin_DecompressVis (byte *in, byte *decompressed)
{
int c;
byte *out;
int row;
// row = (r_numvisleafs+7)>>3;
row = (sin_dvis->numclusters+7)>>3;
out = decompressed;
do
{
if (*in)
{
*out++ = *in++;
continue;
}
c = in[1];
if (!c)
Error ("DecompressVis: 0 repeat");
in += 2;
while (c)
{
*out++ = 0;
c--;
}
} while (out - decompressed < row);
} //end of the function Sin_DecompressVis
//=============================================================================
/*
=============
Sin_SwapBSPFile
Byte swaps all data in a bsp file.
=============
*/
void Sin_SwapBSPFile (qboolean todisk)
{
int i, j;
sin_dmodel_t *d;
// models
for (i=0 ; i<sin_nummodels ; i++)
{
d = &sin_dmodels[i];
d->firstface = LittleLong (d->firstface);
d->numfaces = LittleLong (d->numfaces);
d->headnode = LittleLong (d->headnode);
for (j=0 ; j<3 ; j++)
{
d->mins[j] = LittleFloat(d->mins[j]);
d->maxs[j] = LittleFloat(d->maxs[j]);
d->origin[j] = LittleFloat(d->origin[j]);
}
}
//
// vertexes
//
for (i=0 ; i<sin_numvertexes ; i++)
{
for (j=0 ; j<3 ; j++)
sin_dvertexes[i].point[j] = LittleFloat (sin_dvertexes[i].point[j]);
}
//
// planes
//
for (i=0 ; i<sin_numplanes ; i++)
{
for (j=0 ; j<3 ; j++)
sin_dplanes[i].normal[j] = LittleFloat (sin_dplanes[i].normal[j]);
sin_dplanes[i].dist = LittleFloat (sin_dplanes[i].dist);
sin_dplanes[i].type = LittleLong (sin_dplanes[i].type);
}
//
// sin_texinfos
//
for (i = 0; i < sin_numtexinfo; i++)
{
for (j=0 ; j<8 ; j++)
sin_texinfo[i].vecs[0][j] = LittleFloat (sin_texinfo[i].vecs[0][j]);
#ifdef SIN
sin_texinfo[i].trans_mag = LittleFloat( sin_texinfo[i].trans_mag );
sin_texinfo[i].trans_angle = LittleLong( sin_texinfo[i].trans_angle );
sin_texinfo[i].animtime = LittleFloat( sin_texinfo[i].animtime );
sin_texinfo[i].nonlit = LittleFloat( sin_texinfo[i].nonlit );
sin_texinfo[i].translucence = LittleFloat( sin_texinfo[i].translucence );
sin_texinfo[i].friction = LittleFloat( sin_texinfo[i].friction );
sin_texinfo[i].restitution = LittleFloat( sin_texinfo[i].restitution );
sin_texinfo[i].flags = LittleUnsigned (sin_texinfo[i].flags);
#else
sin_texinfo[i].value = LittleLong (sin_texinfo[i].value);
sin_texinfo[i].flags = LittleLong (sin_texinfo[i].flags);
#endif
sin_texinfo[i].nexttexinfo = LittleLong (sin_texinfo[i].nexttexinfo);
}
#ifdef SIN
//
// lightinfos
//
for (i = 0; i < sin_numlightinfo; i++)
{
for (j=0 ; j<3 ; j++)
{
sin_lightinfo[i].color[j] = LittleFloat (sin_lightinfo[i].color[j]);
}
sin_lightinfo[i].value = LittleLong (sin_lightinfo[i].value);
sin_lightinfo[i].direct = LittleFloat( sin_lightinfo[i].direct );
sin_lightinfo[i].directangle = LittleFloat( sin_lightinfo[i].directangle );
sin_lightinfo[i].directstyle = LittleFloat( sin_lightinfo[i].directstyle );
}
#endif
//
// faces
//
for (i=0 ; i<sin_numfaces ; i++)
{
sin_dfaces[i].texinfo = LittleShort (sin_dfaces[i].texinfo);
#ifdef SIN
sin_dfaces[i].lightinfo = LittleLong (sin_dfaces[i].lightinfo);
sin_dfaces[i].planenum = LittleUnsignedShort (sin_dfaces[i].planenum);
#else
sin_dfaces[i].planenum = LittleShort (sin_dfaces[i].planenum);
#endif
sin_dfaces[i].side = LittleShort (sin_dfaces[i].side);
sin_dfaces[i].lightofs = LittleLong (sin_dfaces[i].lightofs);
sin_dfaces[i].firstedge = LittleLong (sin_dfaces[i].firstedge);
sin_dfaces[i].numedges = LittleShort (sin_dfaces[i].numedges);
}
//
// nodes
//
for (i=0 ; i<sin_numnodes ; i++)
{
sin_dnodes[i].planenum = LittleLong (sin_dnodes[i].planenum);
for (j=0 ; j<3 ; j++)
{
sin_dnodes[i].mins[j] = LittleShort (sin_dnodes[i].mins[j]);
sin_dnodes[i].maxs[j] = LittleShort (sin_dnodes[i].maxs[j]);
}
sin_dnodes[i].children[0] = LittleLong (sin_dnodes[i].children[0]);
sin_dnodes[i].children[1] = LittleLong (sin_dnodes[i].children[1]);
#ifdef SIN
sin_dnodes[i].firstface = LittleUnsignedShort (sin_dnodes[i].firstface);
sin_dnodes[i].numfaces = LittleUnsignedShort (sin_dnodes[i].numfaces);
#else
sin_dnodes[i].firstface = LittleShort (sin_dnodes[i].firstface);
sin_dnodes[i].numfaces = LittleShort (sin_dnodes[i].numfaces);
#endif
}
//
// leafs
//
for (i=0 ; i<sin_numleafs ; i++)
{
sin_dleafs[i].contents = LittleLong (sin_dleafs[i].contents);
sin_dleafs[i].cluster = LittleShort (sin_dleafs[i].cluster);
sin_dleafs[i].area = LittleShort (sin_dleafs[i].area);
for (j=0 ; j<3 ; j++)
{
sin_dleafs[i].mins[j] = LittleShort (sin_dleafs[i].mins[j]);
sin_dleafs[i].maxs[j] = LittleShort (sin_dleafs[i].maxs[j]);
}
#ifdef SIN
sin_dleafs[i].firstleafface = LittleUnsignedShort (sin_dleafs[i].firstleafface);
sin_dleafs[i].numleaffaces = LittleUnsignedShort (sin_dleafs[i].numleaffaces);
sin_dleafs[i].firstleafbrush = LittleUnsignedShort (sin_dleafs[i].firstleafbrush);
sin_dleafs[i].numleafbrushes = LittleUnsignedShort (sin_dleafs[i].numleafbrushes);
#else
sin_dleafs[i].firstleafface = LittleShort (sin_dleafs[i].firstleafface);
sin_dleafs[i].numleaffaces = LittleShort (sin_dleafs[i].numleaffaces);
sin_dleafs[i].firstleafbrush = LittleShort (sin_dleafs[i].firstleafbrush);
sin_dleafs[i].numleafbrushes = LittleShort (sin_dleafs[i].numleafbrushes);
#endif
}
//
// leaffaces
//
for (i=0 ; i<sin_numleaffaces ; i++)
sin_dleaffaces[i] = LittleShort (sin_dleaffaces[i]);
//
// leafbrushes
//
for (i=0 ; i<sin_numleafbrushes ; i++)
sin_dleafbrushes[i] = LittleShort (sin_dleafbrushes[i]);
//
// surfedges
//
for (i=0 ; i<sin_numsurfedges ; i++)
sin_dsurfedges[i] = LittleLong (sin_dsurfedges[i]);
//
// edges
//
for (i=0 ; i<sin_numedges ; i++)
{
#ifdef SIN
sin_dedges[i].v[0] = LittleUnsignedShort (sin_dedges[i].v[0]);
sin_dedges[i].v[1] = LittleUnsignedShort (sin_dedges[i].v[1]);
#else
sin_dedges[i].v[0] = LittleShort (sin_dedges[i].v[0]);
sin_dedges[i].v[1] = LittleShort (sin_dedges[i].v[1]);
#endif
}
//
// brushes
//
for (i=0 ; i<sin_numbrushes ; i++)
{
sin_dbrushes[i].firstside = LittleLong (sin_dbrushes[i].firstside);
sin_dbrushes[i].numsides = LittleLong (sin_dbrushes[i].numsides);
sin_dbrushes[i].contents = LittleLong (sin_dbrushes[i].contents);
}
//
// areas
//
for (i=0 ; i<sin_numareas ; i++)
{
sin_dareas[i].numareaportals = LittleLong (sin_dareas[i].numareaportals);
sin_dareas[i].firstareaportal = LittleLong (sin_dareas[i].firstareaportal);
}
//
// areasportals
//
for (i=0 ; i<sin_numareaportals ; i++)
{
sin_dareaportals[i].portalnum = LittleLong (sin_dareaportals[i].portalnum);
sin_dareaportals[i].otherarea = LittleLong (sin_dareaportals[i].otherarea);
}
//
// brushsides
//
for (i=0 ; i<sin_numbrushsides ; i++)
{
#ifdef SIN
sin_dbrushsides[i].planenum = LittleUnsignedShort (sin_dbrushsides[i].planenum);
#else
sin_dbrushsides[i].planenum = LittleShort (sin_dbrushsides[i].planenum);
#endif
sin_dbrushsides[i].texinfo = LittleShort (sin_dbrushsides[i].texinfo);
#ifdef SIN
sin_dbrushsides[i].lightinfo = LittleLong (sin_dbrushsides[i].lightinfo);
#endif
}
//
// visibility
//
if (todisk)
j = sin_dvis->numclusters;
else
j = LittleLong(sin_dvis->numclusters);
sin_dvis->numclusters = LittleLong (sin_dvis->numclusters);
for (i=0 ; i<j ; i++)
{
sin_dvis->bitofs[i][0] = LittleLong (sin_dvis->bitofs[i][0]);
sin_dvis->bitofs[i][1] = LittleLong (sin_dvis->bitofs[i][1]);
}
} //end of the function Sin_SwapBSPFile
sin_dheader_t *header;
#ifdef SIN
int Sin_CopyLump (int lump, void *dest, int size, int maxsize)
{
int length, ofs;
length = header->lumps[lump].filelen;
ofs = header->lumps[lump].fileofs;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -