DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
svbsp.h File Reference
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  svbsp_node_t
 
struct  svbsp_t
 

Functions

int SVBSP_AddPolygon (svbsp_t *b, int numpoints, const float *points, int insertoccluder, void(*fragmentcallback)(void *fragmentcallback_pointer1, int fragmentcallback_number1, svbsp_t *b, int numpoints, const float *points), void *fragmentcallback_pointer1, int fragmentcallback_number1)
 
void SVBSP_Init (svbsp_t *b, const float *origin, int maxnodes, svbsp_node_t *nodes)
 

Function Documentation

◆ SVBSP_AddPolygon()

int SVBSP_AddPolygon ( svbsp_t * b,
int numpoints,
const float * points,
int insertoccluder,
void(* fragmentcallback )(void *fragmentcallback_pointer1, int fragmentcallback_number1, svbsp_t *b, int numpoints, const float *points),
void * fragmentcallback_pointer1,
int fragmentcallback_number1 )

Definition at line 403 of file svbsp.c.

404{
405 int i;
406 int nodenum;
407 svbsp_polygon_t poly;
408 // don't even consider an empty polygon
409 // note we still allow points and lines to be tested...
410 if (numpoints < 1)
411 return 0;
412 // if the polygon has too many points, we would crash
413 if (numpoints > MAX_SVBSP_POLYGONPOINTS)
414 return 0;
415 poly.numpoints = numpoints;
416 for (i = 0;i < numpoints;i++)
417 {
418 poly.points[i][0] = points[i*3+0];
419 poly.points[i][1] = points[i*3+1];
420 poly.points[i][2] = points[i*3+2];
421 //poly.splitflags[i] = 0; // this edge is a valid BSP splitter - clipped edges are not (because they lie on a bsp plane)
422 poly.facesplitflag = 0; // this face is a valid BSP Splitter - if it lies on a bsp plane it is not
423 }
424#if 0
425//if (insertoccluder)
426 for (i = 0;i < poly.numpoints-2;i++)
427 {
428 Debug_PolygonBegin(NULL, DRAWFLAG_ADDITIVE);
429 Debug_PolygonVertex(poly.points[ 0][0], poly.points[ 0][1], poly.points[ 0][2], 0.0f, 0.0f, 0.0f, 0.25f, 0.0f, 1.0f);
430 Debug_PolygonVertex(poly.points[i+1][0], poly.points[i+1][1], poly.points[i+1][2], 0.0f, 0.0f, 0.0f, 0.25f, 0.0f, 1.0f);
431 Debug_PolygonVertex(poly.points[i+2][0], poly.points[i+2][1], poly.points[i+2][2], 0.0f, 0.0f, 0.0f, 0.25f, 0.0f, 1.0f);
432 Debug_PolygonEnd();
433 }
434#endif
435 nodenum = 0;
436 i = SVBSP_AddPolygonNode(b, &nodenum, -1, &poly, insertoccluder, fragmentcallback, fragmentcallback_pointer1, fragmentcallback_number1);
437 if (insertoccluder)
438 {
439 if (i & 2)
440 b->stat_occluders_accepted++;
441 else
442 b->stat_occluders_rejected++;
443 }
444 else
445 {
446 if (i & 2)
447 b->stat_queries_accepted++;
448 else
449 b->stat_queries_rejected++;
450 }
451 return i;
452}
const float DRAWFLAG_ADDITIVE
int i
#define NULL
Definition qtypes.h:12
dp_FragColor b
int numpoints
Definition svbsp.c:21
float points[MAX_SVBSP_POLYGONPOINTS][3]
Definition svbsp.c:18
int facesplitflag
Definition svbsp.c:20
static int SVBSP_AddPolygonNode(svbsp_t *b, int *parentnodenumpointer, int parentnodenum, const svbsp_polygon_t *poly, int insertoccluder, void(*fragmentcallback)(void *fragmentcallback_pointer1, int fragmentcallback_number1, svbsp_t *b, int numpoints, const float *points), void *fragmentcallback_pointer1, int fragmentcallback_number1)
Definition svbsp.c:273
#define MAX_SVBSP_POLYGONPOINTS
Definition svbsp.c:11

References b, DRAWFLAG_ADDITIVE, svbsp_polygon_t::facesplitflag, i, MAX_SVBSP_POLYGONPOINTS, NULL, svbsp_polygon_t::numpoints, svbsp_polygon_t::points, and SVBSP_AddPolygonNode().

Referenced by Mod_GenerateLightmaps_CreateLights_ComputeSVBSP_InsertSurfaces(), R_Q1BSP_RecursiveGetLightInfo_BIH(), and R_Q1BSP_RecursiveGetLightInfo_BSP().

◆ SVBSP_Init()

void SVBSP_Init ( svbsp_t * b,
const float * origin,
int maxnodes,
svbsp_node_t * nodes )

Definition at line 99 of file svbsp.c.

100{
101 memset(b, 0, sizeof(*b));
102 b->origin[0] = origin[0];
103 b->origin[1] = origin[1];
104 b->origin[2] = origin[2];
105 b->numnodes = 3;
106 b->maxnodes = maxnodes;
107 b->nodes = nodes;
108 b->ranoutofnodes = 0;
109 b->stat_occluders_rejected = 0;
110 b->stat_occluders_accepted = 0;
111 b->stat_occluders_fragments_accepted = 0;
112 b->stat_occluders_fragments_rejected = 0;
113 b->stat_queries_rejected = 0;
114 b->stat_queries_accepted = 0;
115 b->stat_queries_fragments_accepted = 0;
116 b->stat_queries_fragments_rejected = 0;
117
118 // the bsp tree must be initialized to have two perpendicular splits axes
119 // through origin, otherwise the polygon insertions would affect the
120 // opposite side of the tree, which would be disasterous.
121 //
122 // so this code has to make 3 nodes and 4 leafs, and since the leafs are
123 // represented by empty/solid state numbers in this system rather than
124 // actual structs, we only need to make the 3 nodes.
125
126 // root node
127 // this one splits the world into +X and -X sides
128 b->nodes[0].plane[0] = 1;
129 b->nodes[0].plane[1] = 0;
130 b->nodes[0].plane[2] = 0;
131 b->nodes[0].plane[3] = origin[0];
132 b->nodes[0].parent = -1;
133 b->nodes[0].children[0] = 1;
134 b->nodes[0].children[1] = 2;
135
136 // +X side node
137 // this one splits the +X half of the world into +Y and -Y
138 b->nodes[1].plane[0] = 0;
139 b->nodes[1].plane[1] = 1;
140 b->nodes[1].plane[2] = 0;
141 b->nodes[1].plane[3] = origin[1];
142 b->nodes[1].parent = 0;
143 b->nodes[1].children[0] = -1;
144 b->nodes[1].children[1] = -1;
145
146 // -X side node
147 // this one splits the -X half of the world into +Y and -Y
148 b->nodes[2].plane[0] = 0;
149 b->nodes[2].plane[1] = 1;
150 b->nodes[2].plane[2] = 0;
151 b->nodes[2].plane[3] = origin[1];
152 b->nodes[2].parent = 0;
153 b->nodes[2].children[0] = -1;
154 b->nodes[2].children[1] = -1;
155}
vector origin
float plane[4]
Definition svbsp.h:17

References b, origin, and svbsp_node_t::plane.

Referenced by Mod_GenerateLightmaps_CreateLights_ComputeSVBSP(), and R_Q1BSP_CallRecursiveGetLightInfo().