+void R_Q1BSP_CallRecursiveGetLightInfo(r_q1bsp_getlightinfo_t *info, qboolean use_svbsp)
+{
+ if (use_svbsp)
+ {
+ double origin[3];
+ VectorCopy(info->relativelightorigin, origin);
+ if (!r_svbsp.nodes)
+ {
+ r_svbsp.maxnodes = max(r_svbsp.maxnodes, 1<<18);
+ r_svbsp.nodes = Mem_Alloc(r_main_mempool, r_svbsp.maxnodes * sizeof(svbsp_node_t));
+ }
+ info->svbsp_active = true;
+ info->svbsp_insertoccluder = true;
+ for (;;)
+ {
+ SVBSP_Init(&r_svbsp, origin, r_svbsp.maxnodes, r_svbsp.nodes);
+ R_Q1BSP_RecursiveGetLightInfo(info, info->model->brush.data_nodes);
+ // if that failed, retry with more nodes
+ if (r_svbsp.ranoutofnodes)
+ {
+ // an upper limit is imposed
+ if (r_svbsp.maxnodes >= 2<<22)
+ break;
+ Mem_Free(r_svbsp.nodes);
+ r_svbsp.maxnodes *= 2;
+ r_svbsp.nodes = Mem_Alloc(tempmempool, r_svbsp.maxnodes * sizeof(svbsp_node_t));
+ }
+ else
+ break;
+ }
+ // now clear the surfacepvs array because we need to redo it
+ memset(info->outsurfacepvs, 0, (info->model->nummodelsurfaces + 7) >> 3);
+ info->outnumsurfaces = 0;
+ }
+ else
+ info->svbsp_active = false;
+
+ // we HAVE to mark the leaf the light is in as lit, because portals are
+ // irrelevant to a leaf that the light source is inside of
+ // (and they are all facing away, too)
+ {
+ mnode_t *node = info->model->brush.data_nodes;
+ mleaf_t *leaf;
+ while (node->plane)
+ node = node->children[(node->plane->type < 3 ? info->relativelightorigin[node->plane->type] : DotProduct(info->relativelightorigin,node->plane->normal)) < node->plane->dist];
+ leaf = (mleaf_t *)node;
+ info->outmins[0] = min(info->outmins[0], leaf->mins[0]);
+ info->outmins[1] = min(info->outmins[1], leaf->mins[1]);
+ info->outmins[2] = min(info->outmins[2], leaf->mins[2]);
+ info->outmaxs[0] = max(info->outmaxs[0], leaf->maxs[0]);
+ info->outmaxs[1] = max(info->outmaxs[1], leaf->maxs[1]);
+ info->outmaxs[2] = max(info->outmaxs[2], leaf->maxs[2]);
+ if (info->outleafpvs)
+ {
+ int leafindex = leaf - info->model->brush.data_leafs;
+ if (!CHECKPVSBIT(info->outleafpvs, leafindex))
+ {
+ SETPVSBIT(info->outleafpvs, leafindex);
+ info->outleaflist[info->outnumleafs++] = leafindex;
+ }
+ }
+ }
+
+ info->svbsp_insertoccluder = false;
+ R_Q1BSP_RecursiveGetLightInfo(info, info->model->brush.data_nodes);
+ if (developer.integer >= 100 && use_svbsp)
+ {
+ Con_Printf("GetLightInfo: svbsp built with %i nodes, polygon stats:\n", r_svbsp.numnodes);
+ Con_Printf("occluders: %i accepted, %i rejected, %i fragments accepted, %i fragments rejected.\n", r_svbsp.stat_occluders_accepted, r_svbsp.stat_occluders_rejected, r_svbsp.stat_occluders_fragments_accepted, r_svbsp.stat_occluders_fragments_rejected);
+ Con_Printf("queries : %i accepted, %i rejected, %i fragments accepted, %i fragments rejected.\n", r_svbsp.stat_queries_accepted, r_svbsp.stat_queries_rejected, r_svbsp.stat_queries_fragments_accepted, r_svbsp.stat_queries_fragments_rejected);
+ }
+}
+
+void R_Q1BSP_GetLightInfo(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, vec3_t outmins, vec3_t outmaxs, int *outleaflist, unsigned char *outleafpvs, int *outnumleafspointer, int *outsurfacelist, unsigned char *outsurfacepvs, int *outnumsurfacespointer, unsigned char *outshadowtrispvs, unsigned char *outlighttrispvs, unsigned char *visitingleafpvs)