]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - model_brush.c
got rid of Cshader system as it really wasn't helping anything, now all surfaces...
[xonotic/darkplaces.git] / model_brush.c
index f843dbb1ae9c7d7d7abbfb315e78c00e4fc573f1..e3919a63ff8f587002a65158c286b88780956f10 100644 (file)
@@ -441,7 +441,7 @@ loc0:
                        if (t->trace->allsolid)
                                t->trace->startsolid = true;
 #if COLLISIONPARANOID >= 3
-                       Con_Printf("S");
+                       Con_Print("S");
 #endif
                        return HULLCHECKSTATE_SOLID;
                }
@@ -449,7 +449,7 @@ loc0:
                {
                        t->trace->allsolid = false;
 #if COLLISIONPARANOID >= 3
-                       Con_Printf("E");
+                       Con_Print("E");
 #endif
                        return HULLCHECKSTATE_EMPTY;
                }
@@ -475,7 +475,7 @@ loc0:
                if (t2 < 0)
                {
 #if COLLISIONPARANOID >= 3
-                       Con_Printf("<");
+                       Con_Print("<");
 #endif
                        num = node->children[1];
                        goto loc0;
@@ -487,7 +487,7 @@ loc0:
                if (t2 >= 0)
                {
 #if COLLISIONPARANOID >= 3
-                       Con_Printf(">");
+                       Con_Print(">");
 #endif
                        num = node->children[0];
                        goto loc0;
@@ -498,7 +498,7 @@ loc0:
        // the line intersects, find intersection point
        // LordHavoc: this uses the original trace for maximum accuracy
 #if COLLISIONPARANOID >= 3
-       Con_Printf("M");
+       Con_Print("M");
 #endif
        if (plane->type < 3)
        {
@@ -549,7 +549,7 @@ loc0:
        t->trace->fraction = bound(0, midf, 1);
 
 #if COLLISIONPARANOID >= 3
-       Con_Printf("D");
+       Con_Print("D");
 #endif
        return HULLCHECKSTATE_DONE;
 }
@@ -623,7 +623,7 @@ static void Mod_Q1BSP_TraceBox(struct model_s *model, int frame, trace_t *trace,
 #if COLLISIONPARANOID >= 2
        Con_Printf("t(%f %f %f,%f %f %f,%i %f %f %f)", rhc.start[0], rhc.start[1], rhc.start[2], rhc.end[0], rhc.end[1], rhc.end[2], rhc.hull - model->brushq1.hulls, rhc.hull->clip_mins[0], rhc.hull->clip_mins[1], rhc.hull->clip_mins[2]);
        Mod_Q1BSP_RecursiveHullCheck(&rhc, rhc.hull->firstclipnode, 0, 1, rhc.start, rhc.end);
-       Con_Printf("\n");
+       Con_Print("\n");
 #else
        if (DotProduct(rhc.dist, rhc.dist))
                Mod_Q1BSP_RecursiveHullCheck(&rhc, rhc.hull->firstclipnode, 0, 1, rhc.start, rhc.end);
@@ -939,13 +939,10 @@ static void Mod_Q1BSP_LoadTextures(lump_t *l)
                tx->width = 16;
                tx->height = 16;
                tx->skin.base = r_notexture;
-               tx->shader = &Cshader_wall_lightmap;
-               tx->flags = SURF_SOLIDCLIP;
                if (i == loadmodel->brushq1.numtextures - 1)
-               {
-                       tx->flags |= SURF_DRAWTURB | SURF_LIGHTBOTHSIDES;
-                       tx->shader = &Cshader_water;
-               }
+                       tx->flags = SURF_DRAWTURB | SURF_LIGHTBOTHSIDES;
+               else
+                       tx->flags = SURF_LIGHTMAP | SURF_SOLIDCLIP;
                tx->currentframe = tx;
        }
 
@@ -983,7 +980,7 @@ static void Mod_Q1BSP_LoadTextures(lump_t *l)
                }
 
                if ((mtwidth & 15) || (mtheight & 15))
-                       Con_Printf("warning: texture \"%s\" in \"%s\" is not 16 aligned", dmiptex->name, loadmodel->name);
+                       Con_Printf("warning: texture \"%s\" in \"%s\" is not 16 aligned\n", dmiptex->name, loadmodel->name);
 
                // LordHavoc: force all names to lowercase
                for (j = 0;name[j];j++)
@@ -1077,8 +1074,7 @@ static void Mod_Q1BSP_LoadTextures(lump_t *l)
                if (tx->name[0] == '*')
                {
                        // turb does not block movement
-                       tx->flags &= ~SURF_SOLIDCLIP;
-                       tx->flags |= SURF_DRAWTURB | SURF_LIGHTBOTHSIDES;
+                       tx->flags = SURF_DRAWTURB | SURF_LIGHTBOTHSIDES;
                        // LordHavoc: some turbulent textures should be fullbright and solid
                        if (!strncmp(tx->name,"*lava",5)
                         || !strncmp(tx->name,"*teleport",9)
@@ -1086,20 +1082,11 @@ static void Mod_Q1BSP_LoadTextures(lump_t *l)
                                tx->flags |= SURF_DRAWFULLBRIGHT | SURF_DRAWNOALPHA;
                        else
                                tx->flags |= SURF_WATERALPHA;
-                       tx->shader = &Cshader_water;
                }
                else if (tx->name[0] == 's' && tx->name[1] == 'k' && tx->name[2] == 'y')
-               {
-                       tx->flags |= SURF_DRAWSKY;
-                       tx->shader = &Cshader_sky;
-               }
+                       tx->flags = SURF_DRAWSKY | SURF_SOLIDCLIP;
                else
-               {
-                       tx->flags |= SURF_LIGHTMAP;
-                       if (!tx->skin.fog)
-                               tx->flags |= SURF_SHADOWCAST | SURF_SHADOWLIGHT;
-                       tx->shader = &Cshader_wall_lightmap;
-               }
+                       tx->flags = SURF_LIGHTMAP | SURF_SOLIDCLIP;
 
                // start out with no animation
                tx->currentframe = tx;
@@ -1247,9 +1234,9 @@ static void Mod_Q1BSP_LoadLighting(lump_t *l)
                        else
                        {
                                if (fs_filesize == 8)
-                                       Con_Printf("Empty .lit file, ignoring\n");
+                                       Con_Print("Empty .lit file, ignoring\n");
                                else
-                                       Con_Printf("Corrupt .lit file (old version?), ignoring\n");
+                                       Con_Print("Corrupt .lit file (old version?), ignoring\n");
                                Mem_Free(data);
                        }
                }
@@ -1526,7 +1513,7 @@ static void Mod_Q1BSP_LoadTexinfo(lump_t *l)
                {
                        // if texture chosen is NULL or the shader needs a lightmap,
                        // force to notexture water shader
-                       if (out->texture == NULL || out->texture->shader->flags & SHADERFLAGS_NEEDLIGHTMAP)
+                       if (out->texture == NULL || out->texture->flags & SURF_LIGHTMAP)
                                out->texture = loadmodel->brushq1.textures + (loadmodel->brushq1.numtextures - 1);
                }
                else
@@ -1642,7 +1629,7 @@ static void SubdividePolygon(int numverts, float *verts)
        {
                if (subdivpolytriangles >= MAX_SUBDIVPOLYTRIANGLES)
                {
-                       Con_Printf("SubdividePolygon: ran out of triangles in buffer, please increase your r_subdivide_size\n");
+                       Con_Print("SubdividePolygon: ran out of triangles in buffer, please increase your r_subdivide_size\n");
                        return;
                }
 
@@ -1832,7 +1819,7 @@ static void Mod_Q1BSP_LoadFaces(lump_t *l)
                else // LordHavoc: white lighting (bsp version 29)
                        surf->samples = loadmodel->brushq1.lightdata + (i * 3);
 
-               if (surf->texinfo->texture->shader == &Cshader_wall_lightmap)
+               if (surf->texinfo->texture->flags & SURF_LIGHTMAP)
                {
                        if ((surf->extents[0] >> 4) + 1 > (256) || (surf->extents[1] >> 4) + 1 > (256))
                                Host_Error("Bad surface extents");
@@ -1890,7 +1877,7 @@ static void Mod_Q1BSP_LoadFaces(lump_t *l)
                Mod_BuildTriangleNeighbors(mesh->data_neighbor3i, mesh->data_element3i, mesh->num_triangles);
                Mod_BuildTextureVectorsAndNormals(mesh->num_vertices, mesh->num_triangles, mesh->data_vertex3f, mesh->data_texcoordtexture2f, mesh->data_element3i, mesh->data_svector3f, mesh->data_tvector3f, mesh->data_normal3f);
 
-               if (surf->texinfo->texture->shader == &Cshader_wall_lightmap)
+               if (surf->texinfo->texture->flags & SURF_LIGHTMAP)
                {
                        int i, iu, iv, smax, tmax;
                        float u, v, ubase, vbase, uscale, vscale;
@@ -1898,7 +1885,6 @@ static void Mod_Q1BSP_LoadFaces(lump_t *l)
                        smax = surf->extents[0] >> 4;
                        tmax = surf->extents[1] >> 4;
 
-                       surf->flags |= SURF_LIGHTMAP;
                        if (r_miplightmaps.integer)
                        {
                                surf->lightmaptexturestride = smax+1;
@@ -2029,7 +2015,7 @@ static void Mod_Q1BSP_LoadLeafs(lump_t *l)
                if (p >= 0 && out->clusterindex >= 0)
                {
                        if (p >= loadmodel->brushq1.num_compressedpvs)
-                               Con_Printf("Mod_Q1BSP_LoadLeafs: invalid visofs\n");
+                               Con_Print("Mod_Q1BSP_LoadLeafs: invalid visofs\n");
                        else
                                Mod_Q1BSP_DecompressVis(loadmodel->brushq1.data_compressedpvs + p, loadmodel->brushq1.data_compressedpvs + loadmodel->brushq1.num_compressedpvs, loadmodel->brush.data_pvsclusters + out->clusterindex * loadmodel->brush.num_pvsclusterbytes, loadmodel->brush.data_pvsclusters + (out->clusterindex + 1) * loadmodel->brush.num_pvsclusterbytes);
                }
@@ -2522,7 +2508,7 @@ static void Mod_Q1BSP_RecursiveNodePortals(mnode_t *node)
                nodeportalwinding = Winding_Clip(nodeportalwinding, clipplane.normal[0], clipplane.normal[1], clipplane.normal[2], clipplane.dist, true);
                if (!nodeportalwinding)
                {
-                       Con_Printf("Mod_Q1BSP_RecursiveNodePortals: WARNING: new portal was clipped away\n");
+                       Con_Print("Mod_Q1BSP_RecursiveNodePortals: WARNING: new portal was clipped away\n");
                        break;
                }
        }
@@ -2878,8 +2864,9 @@ void Mod_Q1BSP_GetVisible(model_t *model, const vec3_t point, const vec3_t mins,
 
 extern void R_Model_Brush_DrawSky(entity_render_t *ent);
 extern void R_Model_Brush_Draw(entity_render_t *ent);
-extern void R_Model_Brush_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius);
-extern void R_Model_Brush_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor, const matrix4x4_t *matrix_modeltolight, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz, rtexture_t *lightcubemap);
+extern void R_Model_Brush_GetLightInfo(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, vec3_t outmins, vec3_t outmaxs, int *outclusterlist, qbyte *outclusterpvs, int *outnumclusterspointer, int *outsurfacelist, qbyte *outsurfacepvs, int *outnumsurfacespointer);
+extern void R_Model_Brush_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, int numsurfaces, const int *surfacelist);
+extern void R_Model_Brush_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor, const matrix4x4_t *matrix_modeltolight, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz, rtexture_t *lightcubemap, int numsurfaces, const int *surfacelist);
 void Mod_Q1BSP_Load(model_t *mod, void *buffer)
 {
        int i, j, k;
@@ -2996,9 +2983,16 @@ void Mod_Q1BSP_Load(model_t *mod, void *buffer)
                mod->brushq1.firstmodelsurface = bm->firstface;
                mod->brushq1.nummodelsurfaces = bm->numfaces;
 
+               // make the model surface list (used by shadowing/lighting)
+               mod->numsurfaces = mod->brushq1.nummodelsurfaces;
+               mod->surfacelist = Mem_Alloc(originalloadmodel->mempool, mod->numsurfaces * sizeof(*mod->surfacelist));
+               for (j = 0;j < mod->numsurfaces;j++)
+                       mod->surfacelist[j] = mod->brushq1.firstmodelsurface + j;
+
                // this gets altered below if sky is used
                mod->DrawSky = NULL;
                mod->Draw = R_Model_Brush_Draw;
+               mod->GetLightInfo = R_Model_Brush_GetLightInfo;
                mod->DrawShadowVolume = R_Model_Brush_DrawShadowVolume;
                mod->DrawLight = R_Model_Brush_DrawLight;
                if (i != 0)
@@ -3024,7 +3018,7 @@ void Mod_Q1BSP_Load(model_t *mod, void *buffer)
                        for (j = 0, surf = &mod->brushq1.surfaces[mod->brushq1.firstmodelsurface];j < mod->brushq1.nummodelsurfaces;j++, surf++)
                        {
                                // we only need to have a drawsky function if it is used(usually only on world model)
-                               if (surf->texinfo->texture->shader == &Cshader_sky)
+                               if (surf->texinfo->texture->flags & SURF_DRAWSKY)
                                        mod->DrawSky = R_Model_Brush_DrawSky;
                                // LordHavoc: submodels always clip, even if water
                                if (mod->brush.numsubmodels - 1)
@@ -3573,6 +3567,7 @@ static void Mod_Q3BSP_LoadTextures(lump_t *l)
        const char *text;
        int flags;
        char shadername[Q3PATHLENGTH];
+       char sky[Q3PATHLENGTH];
 
        in = (void *)(mod_base + l->fileofs);
        if (l->filelen % sizeof(*in))
@@ -3604,8 +3599,9 @@ static void Mod_Q3BSP_LoadTextures(lump_t *l)
                                text = f;
                                while (COM_ParseToken(&text, false))
                                {
-                                       snprintf(shadername, sizeof(shadername), "%s", com_token);
+                                       strncpy(shadername, com_token, sizeof(shadername));
                                        flags = 0;
+                                       sky[0] = 0;
                                        if (COM_ParseToken(&text, false) && !strcasecmp(com_token, "{"))
                                        {
                                                while (COM_ParseToken(&text, false))
@@ -3690,6 +3686,22 @@ static void Mod_Q3BSP_LoadTextures(lump_t *l)
                                                                        goto parseerror;
                                                                }
                                                        }
+                                                       else if (!strcasecmp(com_token, "sky"))
+                                                       {
+                                                               if (COM_ParseToken(&text, true) && strcasecmp(com_token, "\n"))
+                                                                       if (strlen(com_token) < sizeof(sky))
+                                                                               strcpy(sky, com_token);
+                                                       }
+                                                       else if (!strcasecmp(com_token, "skyparms"))
+                                                       {
+                                                               if (COM_ParseToken(&text, true) && strcasecmp(com_token, "\n"))
+                                                               {
+                                                                       if (strlen(com_token) < sizeof(sky) && !atoi(com_token) && strcasecmp(com_token, "-"))
+                                                                               strcpy(sky, com_token);
+                                                                       if (COM_ParseToken(&text, true) && strcasecmp(com_token, "\n"))
+                                                                               COM_ParseToken(&text, true);
+                                                               }
+                                                       }
                                                        else
                                                        {
                                                                // look for linebreak or }
@@ -3702,8 +3714,14 @@ static void Mod_Q3BSP_LoadTextures(lump_t *l)
                                                // add shader to list (shadername and flags)
                                                // actually here we just poke into the texture settings
                                                for (j = 0, out = loadmodel->brushq3.data_textures;j < loadmodel->brushq3.num_textures;j++, out++)
+                                               {
                                                        if (!strcasecmp(out->name, shadername))
+                                                       {
                                                                out->surfaceparms = flags;
+                                                               if ((flags & Q3SURFACEPARM_SKY) && sky[0])
+                                                                       strcpy(loadmodel->brush.skybox, sky);
+                                                       }
+                                               }
                                        }
                                        else
                                        {
@@ -4255,7 +4273,7 @@ static void Mod_Q3BSP_LoadFaces(lump_t *l)
                                if (out->data_element3i[j] < 0 || out->data_element3i[j] >= out->num_vertices)
                                        out->data_element3i[j] = 0;
                        }
-                       Con_Printf("\n");
+                       Con_Print("\n");
                }
                // for shadow volumes
                Mod_BuildTriangleNeighbors(out->data_neighbor3i, out->data_element3i, out->num_triangles);
@@ -5494,8 +5512,9 @@ void Mod_Q3BSP_GetVisible(model_t *model, const vec3_t point, const vec3_t mins,
 
 extern void R_Q3BSP_DrawSky(struct entity_render_s *ent);
 extern void R_Q3BSP_Draw(struct entity_render_s *ent);
-extern void R_Q3BSP_DrawShadowVolume(struct entity_render_s *ent, vec3_t relativelightorigin, float lightradius);
-extern void R_Q3BSP_DrawLight(struct entity_render_s *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor, const matrix4x4_t *matrix_modeltolight, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz, rtexture_t *lightcubemap);
+extern void R_Q3BSP_GetLightInfo(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, vec3_t outmins, vec3_t outmaxs, int *outclusterlist, qbyte *outclusterpvs, int *outnumclusterspointer, int *outsurfacelist, qbyte *outsurfacepvs, int *outnumsurfacespointer);
+extern void R_Q3BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin, float lightradius, int numsurfaces, const int *surfacelist);
+extern void R_Q3BSP_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, vec3_t relativeeyeorigin, float lightradius, float *lightcolor, const matrix4x4_t *matrix_modeltolight, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz, rtexture_t *lightcubemap, int numsurfaces, const int *surfacelist);
 void Mod_Q3BSP_Load(model_t *mod, void *buffer)
 {
        int i, j, numshadowmeshtriangles;
@@ -5530,6 +5549,7 @@ void Mod_Q3BSP_Load(model_t *mod, void *buffer)
        mod->brush.FindNonSolidLocation = Mod_Q3BSP_FindNonSolidLocation;
        //mod->DrawSky = R_Q3BSP_DrawSky;
        mod->Draw = R_Q3BSP_Draw;
+       mod->GetLightInfo = R_Q3BSP_GetLightInfo;
        mod->DrawShadowVolume = R_Q3BSP_DrawShadowVolume;
        mod->DrawLight = R_Q3BSP_DrawLight;
 
@@ -5599,6 +5619,12 @@ void Mod_Q3BSP_Load(model_t *mod, void *buffer)
                mod->brushq3.data_thismodel = loadmodel->brushq3.data_models + i;
                mod->brushq3.submodel = i;
 
+               // make the model surface list (used by shadowing/lighting)
+               mod->numsurfaces = mod->brushq3.data_thismodel->numfaces;
+               mod->surfacelist = Mem_Alloc(loadmodel->mempool, mod->numsurfaces * sizeof(*mod->surfacelist));
+               for (j = 0;j < mod->numsurfaces;j++)
+                       mod->surfacelist[j] = (mod->brushq3.data_thismodel->firstface - mod->brushq3.data_faces) + j;
+
                VectorCopy(mod->brushq3.data_thismodel->mins, mod->normalmins);
                VectorCopy(mod->brushq3.data_thismodel->maxs, mod->normalmaxs);
                corner[0] = max(fabs(mod->normalmins[0]), fabs(mod->normalmaxs[0]));