]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - model_brush.c
don't send empty lightstyles during signon
[xonotic/darkplaces.git] / model_brush.c
index 0d3f10dca050c78949108b2ac5d452a9c6123804..68554e0dfc69f1d81c96494012fd52bc079a68fb 100644 (file)
@@ -74,8 +74,6 @@ static mleaf_t *Mod_Q1BSP_PointInLeaf(model_t *model, const vec3_t p)
        if (model == NULL)
                return NULL;
 
-       Mod_CheckLoaded(model);
-
        // LordHavoc: modified to start at first clip node,
        // in other words: first node of the (sub)model
        node = model->brush.data_nodes + model->brushq1.hulls[0].firstclipnode;
@@ -104,6 +102,48 @@ static void Mod_Q1BSP_AmbientSoundLevelsForPoint(model_t *model, const vec3_t p,
                memset(out, 0, outsize);
 }
 
+static int Mod_Q1BSP_FindBoxClusters(model_t *model, const vec3_t mins, const vec3_t maxs, int maxclusters, int *clusterlist)
+{
+       int numclusters = 0, side, nodestackindex = 0;
+       mnode_t *node, *nodestack[1024];
+       if (!model->brush.num_pvsclusters)
+               return -1;
+       node = model->brush.data_nodes;
+       for (;;)
+       {
+               if (node->plane)
+               {
+                       // node - recurse down the BSP tree
+                       side = BoxOnPlaneSide(mins, maxs, node->plane) - 1;
+                       if (side < 2)
+                       {
+                               // box is on one side of plane, take that path
+                               node = node->children[side];
+                       }
+                       else
+                       {
+                               // box crosses plane, take one path and remember the other
+                               if (nodestackindex < 1024)
+                                       nodestack[nodestackindex++] = node->children[0];
+                               node = node->children[1];
+                       }
+               }
+               else
+               {
+                       // leaf - check cluster bit
+                       if (numclusters < maxclusters)
+                               clusterlist[numclusters] = ((mleaf_t *)node)->clusterindex;
+                       numclusters++;
+                       // try another path we didn't take earlier
+                       if (nodestackindex == 0)
+                               break;
+                       node = nodestack[--nodestackindex];
+               }
+       }
+       // return number of clusters found (even if more than the maxclusters)
+       return numclusters;
+}
+
 static int Mod_Q1BSP_BoxTouchingPVS(model_t *model, const qbyte *pvs, const vec3_t mins, const vec3_t maxs)
 {
        int clusterindex, side, nodestackindex = 0;
@@ -2813,7 +2853,6 @@ static void Mod_Q1BSP_BuildLightmapUpdateChains(mempool_t *mempool, model_t *mod
 static qbyte *Mod_Q1BSP_GetPVS(model_t *model, const vec3_t p)
 {
        mnode_t *node;
-       Mod_CheckLoaded(model);
        node = model->brush.data_nodes;
        while (node->plane)
                node = node->children[(node->plane->type < 3 ? p[node->plane->type] : DotProduct(p,node->plane->normal)) < node->plane->dist];
@@ -3013,6 +3052,7 @@ void Mod_Q1BSP_Load(model_t *mod, void *buffer, void *bufferend)
        mod->brush.BoxTouchingPVS = Mod_Q1BSP_BoxTouchingPVS;
        mod->brush.BoxTouchingLeafPVS = Mod_Q1BSP_BoxTouchingLeafPVS;
        mod->brush.BoxTouchingVisibleLeafs = Mod_Q1BSP_BoxTouchingVisibleLeafs;
+       mod->brush.FindBoxClusters = Mod_Q1BSP_FindBoxClusters;
        mod->brush.LightPoint = Mod_Q1BSP_LightPoint;
        mod->brush.FindNonSolidLocation = Mod_Q1BSP_FindNonSolidLocation;
        mod->brush.AmbientSoundLevelsForPoint = Mod_Q1BSP_AmbientSoundLevelsForPoint;
@@ -3164,6 +3204,7 @@ void Mod_Q1BSP_Load(model_t *mod, void *buffer, void *bufferend)
                        mod->brush.BoxTouchingPVS = NULL;
                        mod->brush.BoxTouchingLeafPVS = NULL;
                        mod->brush.BoxTouchingVisibleLeafs = NULL;
+                       mod->brush.FindBoxClusters = NULL;
                        mod->brush.LightPoint = NULL;
                        mod->brush.AmbientSoundLevelsForPoint = NULL;
                }
@@ -5514,6 +5555,7 @@ void Mod_Q3BSP_Load(model_t *mod, void *buffer, void *bufferend)
        mod->brush.BoxTouchingPVS = Mod_Q1BSP_BoxTouchingPVS;
        mod->brush.BoxTouchingLeafPVS = Mod_Q1BSP_BoxTouchingLeafPVS;
        mod->brush.BoxTouchingVisibleLeafs = Mod_Q1BSP_BoxTouchingVisibleLeafs;
+       mod->brush.FindBoxClusters = Mod_Q1BSP_FindBoxClusters;
        mod->brush.LightPoint = Mod_Q3BSP_LightPoint;
        mod->brush.FindNonSolidLocation = Mod_Q1BSP_FindNonSolidLocation;
        mod->brush.PointInLeaf = Mod_Q1BSP_PointInLeaf;
@@ -5605,6 +5647,7 @@ void Mod_Q3BSP_Load(model_t *mod, void *buffer, void *bufferend)
                        mod->brush.BoxTouchingPVS = NULL;
                        mod->brush.BoxTouchingLeafPVS = NULL;
                        mod->brush.BoxTouchingVisibleLeafs = NULL;
+                       mod->brush.FindBoxClusters = NULL;
                        mod->brush.LightPoint = NULL;
                        mod->brush.FindNonSolidLocation = Mod_Q1BSP_FindNonSolidLocation;
                }