]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_main.c
Update extension description to prefer "ent" as the parameter name over "e"
[xonotic/darkplaces.git] / cl_main.c
index ca6731aced0a95264487b884f0d79421f63d008a..5d22ba7b6b3a3b1d45be8e9172aaf5cff4ed82c2 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -35,6 +35,7 @@ cvar_t csqc_progname = {CVAR_CLIENT | CVAR_SERVER, "csqc_progname","csprogs.dat"
 cvar_t csqc_progcrc = {CVAR_CLIENT | CVAR_READONLY, "csqc_progcrc","-1","CRC of csprogs.dat file to load (-1 is none), only used during level changes and then reset to -1"};
 cvar_t csqc_progsize = {CVAR_CLIENT | CVAR_READONLY, "csqc_progsize","-1","file size of csprogs.dat file to load (-1 is none), only used during level changes and then reset to -1"};
 cvar_t csqc_usedemoprogs = {CVAR_CLIENT, "csqc_usedemoprogs","1","use csprogs stored in demos"};
+cvar_t csqc_polygons_defaultmaterial_nocullface = {CVAR_CLIENT, "csqc_polygons_defaultmaterial_nocullface", "0", "use 'cull none' behavior in the default shader for rendering R_PolygonBegin - warning: enabling this is not consistent with FTEQW behavior on this feature"};
 
 cvar_t cl_shownet = {CVAR_CLIENT, "cl_shownet","0","1 = print packet size, 2 = print packet message list"};
 cvar_t cl_nolerp = {CVAR_CLIENT, "cl_nolerp", "0","network update smoothing"};
@@ -141,7 +142,6 @@ void CL_ClearState(void)
        cl.max_lightstyle = MAX_LIGHTSTYLES;
        cl.max_brushmodel_entities = MAX_EDICTS;
        cl.max_particles = MAX_PARTICLES_INITIAL; // grows dynamically
-       cl.max_decals = MAX_DECALS_INITIAL; // grows dynamically
        cl.max_showlmps = 0;
 
        cl.num_dlights = 0;
@@ -158,7 +158,6 @@ void CL_ClearState(void)
        cl.lightstyle = (lightstyle_t *)Mem_Alloc(cls.levelmempool, cl.max_lightstyle * sizeof(lightstyle_t));
        cl.brushmodel_entities = (int *)Mem_Alloc(cls.levelmempool, cl.max_brushmodel_entities * sizeof(int));
        cl.particles = (particle_t *) Mem_Alloc(cls.levelmempool, cl.max_particles * sizeof(particle_t));
-       cl.decals = (decal_t *) Mem_Alloc(cls.levelmempool, cl.max_decals * sizeof(decal_t));
        cl.showlmps = NULL;
 
        // LadyHavoc: have to set up the baseline info for alpha and other stuff
@@ -391,12 +390,16 @@ void CL_Disconnect(void)
                NetConn_SendUnreliableMessage(cls.netcon, &buf, cls.protocol, 10000, 0, false);
                NetConn_Close(cls.netcon);
                cls.netcon = NULL;
+               Con_Printf("Disconnected\n");
        }
        cls.state = ca_disconnected;
        cl.islocalgame = false;
 
        cls.demoplayback = cls.timedemo = false;
        cls.signon = 0;
+
+       // If we're dropped mid-connection attempt, it won't clear otherwise.
+       SCR_ClearLoadingScreen(false);
 }
 
 void CL_Disconnect_f(cmd_state_t *cmd)
@@ -429,14 +432,9 @@ void CL_EstablishConnection(const char *host, int firstarg)
 #ifdef CONFIG_MENU
        M_Update_Return_Reason("");
 #endif
-       cls.demonum = -1;
 
-       // stop demo loop in case this fails
-       if (cls.demoplayback)
-               CL_StopPlayback();
-
-       // if downloads are running, cancel their finishing action
-       Curl_Clear_forthismap();
+       // Disconnect from the current server, or stop a running demo.
+       CL_Disconnect();
 
        // make sure the client ports are open before attempting to connect
        NetConn_UpdateSockets();
@@ -1876,6 +1874,8 @@ void CSQC_RelinkAllEntities (int drawmask)
 {
        // link stuff
        CL_RelinkWorld();
+       // the scene mesh is added first for easier debugging (consistent spot in render entities list)
+       CL_MeshEntities_Scene_AddRenderEntity();
        CL_RelinkStaticEntities();
        CL_RelinkBeams();
        CL_RelinkEffects();
@@ -1892,8 +1892,6 @@ void CSQC_RelinkAllEntities (int drawmask)
 
        // update view blend
        V_CalcViewBlend();
-
-       CL_MeshEntities_AddToScene();
 }
 
 /*
@@ -1944,7 +1942,12 @@ void CL_UpdateWorld(void)
 
                // when csqc is loaded, it will call this in CSQC_UpdateView
                if (!cl.csqc_loaded)
+               {
+                       // clear the CL_Mesh_Scene() used for some engine effects
+                       CL_MeshEntities_Scene_Clear();
+                       // add engine entities and effects
                        CSQC_RelinkAllEntities(ENTMASK_ENGINE | ENTMASK_ENGINEVIEWMODELS);
+               }
 
                // decals, particles, and explosions will be updated during rneder
        }
@@ -2192,7 +2195,7 @@ static void CL_Locs_Save_f(cmd_state_t *cmd)
                        if (VectorCompare(loc->mins, loc->maxs))
                                break;
                if (loc)
-                       Con_Printf("Warning: writing loc file containing a mixture of qizmo-style points and proquake-style boxes may not work in qizmo or proquake!\n");
+                       Con_Warnf("Warning: writing loc file containing a mixture of qizmo-style points and proquake-style boxes may not work in qizmo or proquake!\n");
        }
        for (loc = cl.locnodes;loc;loc = loc->next)
        {
@@ -2373,9 +2376,7 @@ entity_t cl_meshentities[NUM_MESHENTITIES];
 dp_model_t cl_meshentitymodels[NUM_MESHENTITIES];
 const char *cl_meshentitynames[NUM_MESHENTITIES] =
 {
-       "MESH_DEBUG",
-       "MESH_CSQC_POLYGONS",
-       "MESH_PARTICLES",
+       "MESH_SCENE",
        "MESH_UI",
 };
 
@@ -2399,7 +2400,8 @@ static void CL_MeshEntities_Init(void)
                ent = cl_meshentities + i;
                ent->state_current.active = true;
                ent->render.model = cl_meshentitymodels + i;
-               ent->render.alpha = 0.999999f; // not quite 1 so that MATERIALFLAG_ALPHA is always set.
+               Mod_Mesh_Create(ent->render.model, cl_meshentitynames[i]);      
+               ent->render.alpha = 1;
                ent->render.flags = RENDER_SHADOW | RENDER_LIGHT;
                ent->render.framegroupblend[0].lerp = 1;
                ent->render.frameblend[0].lerp = 1;
@@ -2423,34 +2425,27 @@ static void CL_MeshEntities_Init(void)
                Matrix4x4_CreateIdentity(&ent->render.matrix);
                CL_UpdateRenderEntity(&ent->render);
        }
+       cl_meshentities[MESH_UI].render.flags = RENDER_NOSELFSHADOW;
        R_RegisterModule("cl_meshentities", CL_MeshEntities_Restart, CL_MeshEntities_Restart, CL_MeshEntities_Restart, CL_MeshEntities_Restart, CL_MeshEntities_Restart);
 }
 
-void CL_MeshEntities_AddToScene(void)
+void CL_MeshEntities_Scene_Clear(void)
 {
-       int i;
-       entity_t *ent;
-       for (i = 0; i < NUM_MESHENTITIES && r_refdef.scene.numentities < r_refdef.scene.maxentities; i++)
-       {
-               ent = cl_meshentities + i;
-               if (ent->render.model->num_surfaces == 0)
-                       continue;
-               Mod_Mesh_Finalize(ent->render.model);
-               VectorCopy(ent->render.model->normalmins, ent->render.mins);
-               VectorCopy(ent->render.model->normalmaxs, ent->render.maxs);
-               r_refdef.scene.entities[r_refdef.scene.numentities++] = &ent->render;
-       }
+       Mod_Mesh_Reset(CL_Mesh_Scene());
 }
 
-void CL_MeshEntities_Reset(void)
+void CL_MeshEntities_Scene_AddRenderEntity(void)
 {
-       int i;
-       entity_t *ent;
-       for (i = 0; i < NUM_MESHENTITIES && r_refdef.scene.numentities < r_refdef.scene.maxentities; i++)
-       {
-               ent = cl_meshentities + i;
-               Mod_Mesh_Reset(ent->render.model);
-       }
+       entity_t* ent = &cl_meshentities[MESH_SCENE];
+       r_refdef.scene.entities[r_refdef.scene.numentities++] = &ent->render;
+}
+
+void CL_MeshEntities_Scene_FinalizeRenderEntity(void)
+{
+       entity_t *ent = &cl_meshentities[MESH_SCENE];
+       Mod_Mesh_Finalize(ent->render.model);
+       VectorCopy(ent->render.model->normalmins, ent->render.mins);
+       VectorCopy(ent->render.model->normalmaxs, ent->render.maxs);
 }
 
 static void CL_MeshEntities_Shutdown(void)
@@ -2494,6 +2489,7 @@ static void CL_UpdateEntityShading_Entity(entity_render_t *ent)
        for (q = 0; q < 3; q++)
                a[q] = c[q] = dir[q] = 0;
 
+       ent->render_lightgrid = false;
        ent->render_modellight_forced = false;
        ent->render_rtlight_disabled = false;
 
@@ -2574,6 +2570,12 @@ static void CL_UpdateEntityShading_Entity(entity_render_t *ent)
                        ent->render_modellight_forced = true;
                        ent->render_rtlight_disabled = true;
                }
+               else if (((ent->model && !ent->model->lit) || (ent->model == r_refdef.scene.worldmodel ? mod_q3bsp_lightgrid_world_surfaces.integer : mod_q3bsp_lightgrid_bsp_surfaces.integer))
+                       && r_refdef.scene.worldmodel && r_refdef.scene.worldmodel->lit && r_refdef.scene.worldmodel->brushq3.lightgridtexture && mod_q3bsp_lightgrid_texture.integer)
+               {
+                       ent->render_lightgrid = true;
+                       // no need to call R_CompleteLightPoint as we base it on render_lightmap_*
+               }
                else if (r_refdef.scene.worldmodel && r_refdef.scene.worldmodel->lit && r_refdef.scene.worldmodel->brush.LightPoint)
                        R_CompleteLightPoint(a, c, dir, shadingorigin, LP_LIGHTMAP, r_refdef.scene.lightmapintensity, r_refdef.scene.ambientintensity);
                else if (r_fullbright_directed.integer)
@@ -2746,6 +2748,8 @@ void CL_Init (void)
        Cmd_AddCommand(&cmd_client, "locs_reload", CL_Locs_Reload_f, "reload .loc file for this map");
        Cmd_AddCommand(&cmd_client, "locs_save", CL_Locs_Save_f, "save .loc file for this map containing currently defined points and boxes");
 
+       Cvar_RegisterVariable(&csqc_polygons_defaultmaterial_nocullface);
+
        CL_Parse_Init();
        CL_Particles_Init();
        CL_Screen_Init();