29 #include "../idlib/precompiled.h"
34 #define MAX_BOUNDS_AREAS 16
111 for ( i = 0; i < na; i++ ) {
143 area->
portals = portalPtrs + cp;
147 for ( j = 0; j <
n; j++ ) {
222 if ( !( portal->
mightSee[ n>>3 ] & (1 << (n&7)) ) ) {
226 if ( portal->
vis[ n>>3 ] & (1 << (n&7)) ) {
230 portal->
vis[ n>>3 ] |= (1 << (n&7));
242 int i,
j, k,
n,
p, side1, side2, areaSide;
309 p1->
mightSee[ n >> 3 ] |= 1 << (n&7);
332 long *sourceVis, *passageVis, *portalVis, *
mightSee, *prevMightSee, more;
336 stack = prevStack->
next;
342 prevStack->
next = stack;
359 if ( !( prevStack->
mightSee[n >> 3] & (1 << (n & 7)) ) ) {
364 source->
vis[n >> 3] |= (1 << (n & 7));
367 prevMightSee =
reinterpret_cast<long *
>(prevStack->
mightSee);
368 passageVis =
reinterpret_cast<long *
>(passage->
canSee);
369 sourceVis =
reinterpret_cast<long *
>(source->
vis);
370 mightSee =
reinterpret_cast<long *
>(stack->
mightSee);
375 portalVis =
reinterpret_cast<long *
>(p->
vis);
378 m = *prevMightSee++ & *passageVis++ & *portalVis++;
380 more |= (m & ~(*sourceVis++));
389 m = *prevMightSee++ & *passageVis++;
391 more |= (m & ~(*sourceVis++));
437 for ( s = stack;
s; s = stack ) {
455 bool flipTest, front;
463 v1 = source[
l].ToVec3() - source[
i].ToVec3();
470 v2 = pass[
j].ToVec3() - source[
i].ToVec3();
472 normal = v1.
Cross( v2 );
476 dist = normal * pass[
j].ToVec3();
484 if ( k == i || k == l ) {
487 d = source[k].ToVec3() * normal - dist;
518 d = pass[k].ToVec3() * normal - dist;
544 for ( k = 0; k < numBounds; k++ ) {
545 if ( plane.
Compare( bounds[k], 0.001f, 0.01f ) ) {
549 if ( k < numBounds ) {
553 if ( numBounds >= maxBounds ) {
557 bounds[numBounds] = plane;
569 #define MAX_PASSAGE_BOUNDS 128
572 int i,
j,
l,
n, numBounds, front, passageMemory, byteNum, bitNum;
595 if ( !( source->
mightSee[ n>>3 ] & (1 << (n&7)) ) ) {
617 for ( bitNum = 0; bitNum < 8; bitNum++ ) {
621 if ( !( mightSee & bit ) ) {
625 p = &pvsPortals[(byteNum << 3) + bitNum];
631 for ( front = 0, l = 0; l < numBounds; l++ ) {
643 if ( l < numBounds ) {
648 if ( front != numBounds ) {
652 for ( l = 0; l < numBounds; l++ ) {
665 if ( l < numBounds ) {
674 passage->
canSee[byteNum] = canSee;
678 passage->
canSee[n >> 3] |= (1 << (n&7));
681 if ( passageMemory < 1024 ) {
682 gameLocal.
Printf(
"%5d bytes passage memory used to build PVS\n", passageMemory );
685 gameLocal.
Printf(
"%5d KB passage memory used to build PVS\n", passageMemory>>10 );
732 int i,
j, k, areaNum, totalVisibleAreas;
734 byte *pvs, *portalPVS;
737 totalVisibleAreas = 0;
740 return totalVisibleAreas;
750 pvs[ i >> 3 ] |= 1 << (i & 7);
758 p1 =
reinterpret_cast<long *
>(area->
portals[0]->
vis);
759 p2 =
reinterpret_cast<long *
>(area->
portals[
j]->
vis);
768 area->
portals[0]->
vis[ k >> 3 ] |= 1 << (k & 7);
775 if ( portalPVS[j>>3] & (1 << (j&7)) ) {
777 pvs[ areaNum >> 3 ] |= 1 << (areaNum & 7);
783 if ( pvs[j>>3] & (1 << (j&7)) ) {
788 return totalVisibleAreas;
797 int totalVisibleAreas;
848 if (
numAreas * areaVisBytes < 1024 ) {
890 int curArea, nextArea;
891 int queueStart, queueEnd;
897 areas[srcArea] =
true;
899 for ( curArea = srcArea; queueStart < queueEnd; curArea =
areaQueue[++queueStart] ) {
903 for ( i = 0; i <
n; i++ ) {
911 nextArea = portal.
areas[1];
914 if ( areas[nextArea] ) {
920 areas[nextArea] =
true;
978 handle =
AllocCurrentPVS( *reinterpret_cast<const unsigned int *>(&sourceArea) );
980 if ( sourceArea < 0 || sourceArea >=
numAreas ) {
1020 for ( i = 0; i < numSourceAreas; i++ ) {
1021 h ^= *
reinterpret_cast<const unsigned int *
>(&sourceAreas[
i]);
1025 if ( !numSourceAreas || sourceAreas[0] < 0 || sourceAreas[0] >=
numAreas) {
1033 for ( i = 1; i < numSourceAreas; i++ ) {
1054 for ( i = 0; i < numSourceAreas; i++ ) {
1077 long *pvs1Ptr, *pvs2Ptr, *ptr;
1092 *ptr++ = *pvs1Ptr++ | *pvs2Ptr++;
1149 if ( targetArea == -1 ) {
1153 return ( (
currentPVS[handle.
i].
pvs[targetArea>>3] & (1 << (targetArea&7)) ) != 0 );
1171 for ( i = 0; i < numTargetAreas; i++ ) {
1172 if (
currentPVS[handle.
i].
pvs[targetAreas[i]>>3] & (1 << (targetAreas[i]&7)) ) {
1191 if ( targetArea < 0 || targetArea >=
numAreas ) {
1195 return ( (
currentPVS[handle.
i].
pvs[targetArea>>3] & (1 << (targetArea&7)) ) != 0 );
1211 for ( i = 0; i < numTargetAreas; i++ ) {
1212 if ( targetAreas[i] < 0 || targetAreas[i] >=
numAreas ) {
1215 if (
currentPVS[handle.
i].
pvs[targetAreas[i]>>3] & (1 << (targetAreas[i]&7)) ) {
1228 int i,
j, k, numPoints,
n, sourceArea;
1237 if ( sourceArea == -1 ) {
1249 if ( j == sourceArea ) {
1259 for ( i = 0; i <
n; i++ ) {
1265 offset = plane.
Normal() * 4.0f;
1266 for ( k = 0; k < numPoints; k++ ) {
1302 for ( i = 0; i <
num; i++ ) {
1303 if ( j == areas[i] ) {
1317 for ( i = 0; i <
n; i++ ) {
1323 offset = plane.
Normal() * 4.0f;
1324 for ( k = 0; k < numPoints; k++ ) {
1339 int i,
j, k, numPoints,
n, sourceArea;
1352 if ( sourceArea == -1 ) {
1362 if ( j == sourceArea ) {
1372 for ( i = 0; i <
n; i++ ) {
1378 offset = plane.
Normal() * 4.0f;
1379 for ( k = 0; k < numPoints; k++ ) {
1430 bool idPVS::CheckAreasForPortalSky(
const pvsHandle_t handle,
const idVec3 &origin ) {
1439 if ( sourceArea == -1 ) {
void GetBounds(idBounds &bounds) const
int GetPortalCount(void) const
assert(prefInfo.fullscreenBtn)
const idVec3 & Normal(void) const
bool Compare(const idPlane &p) const
#define MAX_PASSAGE_BOUNDS
void Printf(const char *fmt,...) const id_attribute((format(printf
void FreeCurrentPVS(pvsHandle_t handle) const
void DrawCurrentPVS(const pvsHandle_t handle, const idVec3 &source) const
void void void void void Error(const char *fmt,...) const id_attribute((format(printf
virtual int NumPortalsInArea(int areaNum)=0
int GetPVSAreas(const idBounds &bounds, int *areas, int maxAreas) const
void DrawPVS(const idVec3 &source, const pvsType_t type=PVS_NORMAL) const
struct pvsStack_s pvsStack_t
pvsHandle_t MergeCurrentPVS(pvsHandle_t pvs1, pvsHandle_t pvs2) const
GLuint GLuint GLsizei GLenum type
struct pvsPassage_s pvsPassage_t
void SetNormal(const idVec3 &normal)
double Milliseconds(void) const
idVec3 Cross(const idVec3 &a) const
struct pvsStack_s * FloodPassagePVS_r(struct pvsPortal_s *source, const struct pvsPortal_s *portal, struct pvsStack_s *prevStack) const
virtual bool CheckAreaForPortalSky(int areaNum)=0
int ReadData(void *data, int length) const
void WriteData(const void *data, int length)
void FloodFrontPortalPVS_r(struct pvsPortal_s *portal, int areaNum) const
void void void Warning(const char *fmt,...) const id_attribute((format(printf
pvsHandle_t SetupCurrentPVS(const idVec3 &source, const pvsType_t type=PVS_NORMAL) const
GLsizei GLsizei GLcharARB * source
GLfloat GLfloat GLfloat v2
void DestroyPassages(void) const
virtual void DebugLine(const idVec4 &color, const idVec3 &start, const idVec3 &end, const int lifetime=0, const bool depthTest=false)=0
int GetNumPoints(void) const
bool InCurrentPVS(const pvsHandle_t handle, const idVec3 &target) const
void SetDist(const float dist)
virtual exitPortal_t GetPortal(int areaNum, int portalNum)=0
struct pvsPortal_s * pvsPortals
void GetPlane(idVec3 &normal, float &dist) const
struct pvsArea_s * pvsAreas
void GetConnectedAreas(int srcArea, bool *connectedAreas) const
void CreatePassages(void) const
struct pvsPortal_s pvsPortal_t
virtual void Printf(const char *fmt,...) id_attribute((format(printf
int Side(const idVec3 &v, const float epsilon=0.0f) const
void AddPassageBoundaries(const idWinding &source, const idWinding &pass, bool flipClip, idPlane *bounds, int &numBounds, int maxBounds) const
struct pvsArea_s pvsArea_t
void CopyPortalPVSToMightSee(void) const
pvsCurrent_t currentPVS[MAX_CURRENT_PVS]
virtual int NumAreas(void) const =0
idWinding * Copy(void) const
int AreaPVSFromPortalPVS(void) const
void PassagePVS(void) const
const idVec3 & ToVec3(void) const
idRenderWorld * gameRenderWorld
virtual int PointInArea(const idVec3 &point) const =0
int PlaneSide(const idPlane &plane, const float epsilon=ON_EPSILON) const
void FrontPortalPVS(void) const
void DestroyPVSData(void)
bool ClipInPlace(const idPlane &plane, const float epsilon=ON_EPSILON, const bool keepOn=false)
pvsHandle_t AllocCurrentPVS(unsigned int h) const
virtual int BoundsInAreas(const idBounds &bounds, int *areas, int maxAreas) const =0
int GetPVSArea(const idVec3 &point) const