]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_main.c
dynamically grow maxtempentities
[xonotic/darkplaces.git] / cl_main.c
index 75239c0863abafbc10a1d1fd1764c34fc69fa384..e5f6fef1cd9c2166375966332043f379e6e7968a 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -57,6 +57,7 @@ cvar_t freelook = {CVAR_SAVE, "freelook", "1","mouse controls pitch instead of f
 
 cvar_t cl_autodemo = {CVAR_SAVE, "cl_autodemo", "0", "records every game played, using the date/time and map name to name the demo file" };
 cvar_t cl_autodemo_nameformat = {CVAR_SAVE, "cl_autodemo_nameformat", "autodemos/%Y-%m-%d_%H-%M", "The format of the cl_autodemo filename, followed by the map name (the date is encoded using strftime escapes)" };
+cvar_t cl_autodemo_delete = {0, "cl_autodemo_delete", "0", "Delete demos after recording.  This is a bitmask, bit 1 gives the default, bit 0 the value for the current demo.  Thus, the values are: 0 = disabled; 1 = delete current demo only; 2 = delete all demos except the current demo; 3 = delete all demos from now on" };
 
 cvar_t r_draweffects = {0, "r_draweffects", "1","renders temporary sprite effects"};
 
@@ -84,6 +85,7 @@ cvar_t cl_dlights_decaybrightness = {CVAR_SAVE, "cl_dlights_decaybrightness", "1
 cvar_t qport = {0, "qport", "0", "identification key for playing on qw servers (allows you to maintain a connection to a quakeworld server even if your port changes)"};
 
 cvar_t cl_prydoncursor = {0, "cl_prydoncursor", "0", "enables a mouse pointer which is able to click on entities in the world, useful for point and click mods, see PRYDON_CLIENTCURSOR extension in dpextensions.qc"};
+cvar_t cl_prydoncursor_notrace = {0, "cl_prydoncursor_notrace", "0", "disables traceline used in prydon cursor reporting to the game, saving some cpu time"};
 
 cvar_t cl_deathnoviewmodel = {0, "cl_deathnoviewmodel", "1", "hides gun model when dead"};
 
@@ -120,7 +122,7 @@ void CL_ClearState(void)
        cl.sensitivityscale = 1.0f;
 
        // enable rendering of the world and such
-       cl.csqc_vidvars.drawworld = true;
+       cl.csqc_vidvars.drawworld = r_drawworld.integer != 0;
        cl.csqc_vidvars.drawenginesbar = true;
        cl.csqc_vidvars.drawcrosshair = true;
 
@@ -133,15 +135,15 @@ void CL_ClearState(void)
 
        // tweak these if the game runs out
        cl.max_csqcrenderentities = 0;
-       cl.max_entities = 256;
-       cl.max_static_entities = 256;
-       cl.max_effects = 256;
-       cl.max_beams = 256;
+       cl.max_entities = MAX_ENITIES_INITIAL;
+       cl.max_static_entities = MAX_STATICENTITIES;
+       cl.max_effects = MAX_EFFECTS;
+       cl.max_beams = MAX_BEAMS;
        cl.max_dlights = MAX_DLIGHTS;
        cl.max_lightstyle = MAX_LIGHTSTYLES;
        cl.max_brushmodel_entities = MAX_EDICTS;
-       cl.max_particles = 8192; // grows dynamically
-       cl.max_decals = 2048; // grows dynamically
+       cl.max_particles = MAX_PARTICLES_INITIAL; // grows dynamically
+       cl.max_decals = MAX_DECALS_INITIAL; // grows dynamically
        cl.max_showlmps = 0;
 
        cl.num_dlights = 0;
@@ -169,7 +171,7 @@ void CL_ClearState(void)
                cl.entities[i].state_current = defaultstate;
        }
 
-       if (gamemode == GAME_NEXUIZ)
+       if (gamemode == GAME_NEXUIZ || gamemode == GAME_XONOTIC)
        {
                VectorSet(cl.playerstandmins, -16, -16, -24);
                VectorSet(cl.playerstandmaxs, 16, 16, 45);
@@ -295,6 +297,7 @@ void CL_ExpandEntities(int num)
 
 void CL_ExpandCSQCRenderEntities(int num)
 {
+       int i;
        int oldmaxcsqcrenderentities;
        entity_render_t *oldcsqcrenderentities;
        if (num >= cl.max_csqcrenderentities)
@@ -308,6 +311,9 @@ void CL_ExpandCSQCRenderEntities(int num)
                if (oldcsqcrenderentities)
                {
                        memcpy(cl.csqcrenderentities, oldcsqcrenderentities, oldmaxcsqcrenderentities * sizeof(entity_render_t));
+                       for (i = 0;i < r_refdef.scene.numentities;i++)
+                               if(r_refdef.scene.entities[i] >= oldcsqcrenderentities && r_refdef.scene.entities[i] < (oldcsqcrenderentities + oldmaxcsqcrenderentities))
+                                       r_refdef.scene.entities[i] = cl.csqcrenderentities + (r_refdef.scene.entities[i] - oldcsqcrenderentities);
                        Mem_Free(oldcsqcrenderentities);
                }
        }
@@ -405,7 +411,7 @@ CL_EstablishConnection
 Host should be either "local" or a net address
 =====================
 */
-void CL_EstablishConnection(const char *host)
+void CL_EstablishConnection(const char *host, int firstarg)
 {
        if (cls.state == ca_dedicated)
                return;
@@ -432,7 +438,24 @@ void CL_EstablishConnection(const char *host)
                cls.connect_trying = true;
                cls.connect_remainingtries = 3;
                cls.connect_nextsendtime = 0;
+
+               // only NOW, set connect_userinfo
+               if(firstarg >= 0)
+               {
+                       int i;
+                       *cls.connect_userinfo = 0;
+                       for(i = firstarg; i+2 <= Cmd_Argc(); i += 2)
+                               InfoString_SetValue(cls.connect_userinfo, sizeof(cls.connect_userinfo), Cmd_Argv(i), Cmd_Argv(i+1));
+               }
+               else if(firstarg < -1)
+               {
+                       // -1: keep as is (reconnect)
+                       // -2: clear
+                       *cls.connect_userinfo = 0;
+               }
+
                M_Update_Return_Reason("Trying to connect...");
+
                // run several network frames to jump into the game quickly
                //if (sv.active)
                //{
@@ -607,6 +630,14 @@ static float CL_LerpPoint(void)
 void CL_ClearTempEntities (void)
 {
        r_refdef.scene.numtempentities = 0;
+       // grow tempentities buffer on request
+       if (r_refdef.scene.expandtempentities)
+       {
+               Con_Printf("CL_NewTempEntity: grow maxtempentities from %i to %i\n", r_refdef.scene.maxtempentities, r_refdef.scene.maxtempentities * 2);
+               r_refdef.scene.maxtempentities *= 2;
+               r_refdef.scene.tempentities = (entity_render_t *)Mem_Realloc(cls.permanentmempool, r_refdef.scene.tempentities, sizeof(entity_render_t) * r_refdef.scene.maxtempentities);
+               r_refdef.scene.expandtempentities = false;
+       }
 }
 
 entity_render_t *CL_NewTempEntity(double shadertime)
@@ -616,7 +647,10 @@ entity_render_t *CL_NewTempEntity(double shadertime)
        if (r_refdef.scene.numentities >= r_refdef.scene.maxentities)
                return NULL;
        if (r_refdef.scene.numtempentities >= r_refdef.scene.maxtempentities)
+       {
+               r_refdef.scene.expandtempentities = true; // will be reallocated next frame since current frame may have pointers set already
                return NULL;
+       }
        render = &r_refdef.scene.tempentities[r_refdef.scene.numtempentities++];
        memset (render, 0, sizeof(*render));
        r_refdef.scene.entities[r_refdef.scene.numentities++] = render;
@@ -903,6 +937,7 @@ void CL_UpdateNetworkEntity(entity_t *e, int recursionlimit, qboolean interpolat
        int frame;
        float origin[3], angles[3], lerp;
        entity_t *t;
+       entity_render_t *r;
        //entity_persistent_t *p = &e->persistent;
        //entity_render_t *r = &e->render;
        // skip inactive entities and world
@@ -935,22 +970,33 @@ void CL_UpdateNetworkEntity(entity_t *e, int recursionlimit, qboolean interpolat
                        return;
                t = cl.entities + e->state_current.tagentity;
                // if the tag entity is inactive, skip it
-               if (!t->state_current.active)
-                       return;
-               // update the parent first
-               CL_UpdateNetworkEntity(t, recursionlimit - 1, interpolate);
+               if (t->state_current.active)
+               {
+                       // update the parent first
+                       CL_UpdateNetworkEntity(t, recursionlimit - 1, interpolate);
+                       r = &t->render;
+               }
+               else
+               {
+                       // it may still be a CSQC entity... trying to use its
+                       // info from last render frame (better than nothing)
+                       if(!cl.csqc_server2csqcentitynumber[e->state_current.tagentity])
+                               return;
+                       r = cl.csqcrenderentities + cl.csqc_server2csqcentitynumber[e->state_current.tagentity];
+                       if(!r->entitynumber)
+                               return; // neither CSQC nor legacy entity... can't attach
+               }
                // make relative to the entity
-               matrix = &t->render.matrix;
+               matrix = &r->matrix;
                // some properties of the tag entity carry over
-               e->render.flags |= t->render.flags & (RENDER_EXTERIORMODEL | RENDER_VIEWMODEL);
+               e->render.flags |= r->flags & (RENDER_EXTERIORMODEL | RENDER_VIEWMODEL);
                // if a valid tagindex is used, make it relative to that tag instead
-               // FIXME: use a model function to get tag info (need to handle skeletal)
-               if (e->state_current.tagentity && e->state_current.tagindex >= 1 && t->render.model)
+               if (e->state_current.tagentity && e->state_current.tagindex >= 1 && r->model)
                {
-                       if(!Mod_Alias_GetTagMatrix(t->render.model, t->render.frameblend, t->render.skeleton, e->state_current.tagindex - 1, &blendmatrix)) // i.e. no error
+                       if(!Mod_Alias_GetTagMatrix(r->model, r->frameblend, r->skeleton, e->state_current.tagindex - 1, &blendmatrix)) // i.e. no error
                        {
                                // concat the tag matrices onto the entity matrix
-                               Matrix4x4_Concat(&tempmatrix, &t->render.matrix, &blendmatrix);
+                               Matrix4x4_Concat(&tempmatrix, &r->matrix, &blendmatrix);
                                // use the constructed tag matrix
                                matrix = &tempmatrix;
                        }
@@ -1157,15 +1203,15 @@ void CL_UpdateNetworkEntityTrail(entity_t *e)
        {
                if (e->render.effects & EF_BRIGHTFIELD)
                {
-                       if (gamemode == GAME_NEXUIZ)
+                       if (gamemode == GAME_NEXUIZ || gamemode == GAME_XONOTIC)
                                trailtype = EFFECT_TR_NEXUIZPLASMA;
                        else
                                CL_EntityParticles(e);
                }
                if (e->render.effects & EF_FLAME)
-                       CL_ParticleTrail(EFFECT_EF_FLAME, bound(0, cl.time - cl.oldtime, 0.1), origin, origin, vec3_origin, vec3_origin, NULL, 0, false, true);
+                       CL_ParticleTrail(EFFECT_EF_FLAME, bound(0, cl.time - cl.oldtime, 0.1), origin, origin, vec3_origin, vec3_origin, NULL, 0, false, true, NULL, NULL);
                if (e->render.effects & EF_STARDUST)
-                       CL_ParticleTrail(EFFECT_EF_STARDUST, bound(0, cl.time - cl.oldtime, 0.1), origin, origin, vec3_origin, vec3_origin, NULL, 0, false, true);
+                       CL_ParticleTrail(EFFECT_EF_STARDUST, bound(0, cl.time - cl.oldtime, 0.1), origin, origin, vec3_origin, vec3_origin, NULL, 0, false, true, NULL, NULL);
        }
        if (e->render.internaleffects & (INTEF_FLAG1QW | INTEF_FLAG2QW))
        {
@@ -1209,7 +1255,7 @@ void CL_UpdateNetworkEntityTrail(entity_t *e)
                if (len > 0)
                        len = 1.0f / len;
                VectorScale(vel, len, vel);
-               CL_ParticleTrail(trailtype, 1, e->persistent.trail_origin, origin, vel, vel, e, e->state_current.glowcolor, false, true);
+               CL_ParticleTrail(trailtype, 1, e->persistent.trail_origin, origin, vel, vel, e, e->state_current.glowcolor, false, true, NULL, NULL);
        }
        // now that the entity has survived one trail update it is allowed to
        // leave a real trail on later frames
@@ -1353,7 +1399,13 @@ void CL_LinkNetworkEntity(entity_t *e)
                        return;
                // if the tag entity is inactive, skip it
                if (!cl.entities[e->state_current.tagentity].state_current.active)
-                       return;
+               {
+                       if(!cl.csqc_server2csqcentitynumber[e->state_current.tagentity])
+                               return;
+                       if(!cl.csqcrenderentities[cl.csqc_server2csqcentitynumber[e->state_current.tagentity]].entitynumber)
+                               return;
+                       // if we get here, it's properly csqc networked and attached
+               }
        }
 
        // create entity dlights associated with this entity
@@ -1376,7 +1428,7 @@ void CL_LinkNetworkEntity(entity_t *e)
        {
                if (e->render.effects & EF_BRIGHTFIELD)
                {
-                       if (gamemode == GAME_NEXUIZ)
+                       if (gamemode == GAME_NEXUIZ || gamemode == GAME_XONOTIC)
                                trailtype = EFFECT_TR_NEXUIZPLASMA;
                }
                if (e->render.effects & EF_DIMLIGHT)
@@ -1409,9 +1461,9 @@ void CL_LinkNetworkEntity(entity_t *e)
                        dlightcolor[2] += 1.50f;
                }
                if (e->render.effects & EF_FLAME)
-                       CL_ParticleTrail(EFFECT_EF_FLAME, 0, origin, origin, vec3_origin, vec3_origin, NULL, 0, true, false);
+                       CL_ParticleTrail(EFFECT_EF_FLAME, 1, origin, origin, vec3_origin, vec3_origin, NULL, 0, true, false, NULL, NULL);
                if (e->render.effects & EF_STARDUST)
-                       CL_ParticleTrail(EFFECT_EF_STARDUST, 0, origin, origin, vec3_origin, vec3_origin, NULL, 0, true, false);
+                       CL_ParticleTrail(EFFECT_EF_STARDUST, 1, origin, origin, vec3_origin, vec3_origin, NULL, 0, true, false, NULL, NULL);
        }
        // muzzleflash fades over time, and is offset a bit
        if (e->persistent.muzzleflash > 0 && r_refdef.scene.numlights < MAX_DLIGHTS)
@@ -1421,7 +1473,7 @@ void CL_LinkNetworkEntity(entity_t *e)
                trace_t trace;
                matrix4x4_t tempmatrix;
                Matrix4x4_Transform(&e->render.matrix, muzzleflashorigin, v2);
-               trace = CL_TraceLine(origin, v2, MOVE_NOMONSTERS, NULL, SUPERCONTENTS_SOLID | SUPERCONTENTS_SKY, true, false, NULL, false);
+               trace = CL_TraceLine(origin, v2, MOVE_NOMONSTERS, NULL, SUPERCONTENTS_SOLID | SUPERCONTENTS_SKY, true, false, NULL, false, false);
                Matrix4x4_Normalize(&tempmatrix, &e->render.matrix);
                Matrix4x4_SetOrigin(&tempmatrix, trace.endpos[0], trace.endpos[1], trace.endpos[2]);
                Matrix4x4_Scale(&tempmatrix, 150, 1);
@@ -1491,12 +1543,8 @@ void CL_LinkNetworkEntity(entity_t *e)
        if (e->render.flags & RENDER_GLOWTRAIL)
                trailtype = EFFECT_TR_GLOWTRAIL;
        if (trailtype)
-               CL_ParticleTrail(trailtype, 0, origin, origin, vec3_origin, vec3_origin, NULL, e->state_current.glowcolor, true, false);
+               CL_ParticleTrail(trailtype, 1, origin, origin, vec3_origin, vec3_origin, NULL, e->state_current.glowcolor, true, false, NULL, NULL);
 
-       // don't show viewmodels in certain situations
-       if (e->render.flags & RENDER_VIEWMODEL)
-               if (!r_drawviewmodel.integer || chase_active.integer || r_refdef.envmap)
-                       return;
        // don't show entities with no modelindex (note: this still shows
        // entities which have a modelindex that resolved to a NULL model)
        if (e->render.model && !(e->render.effects & EF_NODRAW) && r_refdef.scene.numentities < r_refdef.scene.maxentities)
@@ -1844,7 +1892,7 @@ void CL_UpdateWorld(void)
        r_refdef.scene.numlights = 0;
        r_refdef.view.matrix = identitymatrix;
        r_refdef.view.quality = 1;
-
+               
        cl.num_brushmodel_entities = 0;
 
        if (cls.state == ca_connected && cls.signon == SIGNONS)
@@ -1928,6 +1976,32 @@ static void CL_Fog_f (void)
                r_refdef.fog_fadedepth = atof(Cmd_Argv(9));
 }
 
+/*
+======================
+CL_FogHeightTexture_f
+======================
+*/
+static void CL_Fog_HeightTexture_f (void)
+{
+       if (Cmd_Argc () < 11)
+       {
+               Con_Printf("\"fog_heighttexture\" is \"%f %f %f %f %f %f %f %f %f %s\"\n", r_refdef.fog_density, r_refdef.fog_red, r_refdef.fog_green, r_refdef.fog_blue, r_refdef.fog_alpha, r_refdef.fog_start, r_refdef.fog_end, r_refdef.fog_height, r_refdef.fog_fadedepth, r_refdef.fog_height_texturename);
+               return;
+       }
+       FOG_clear(); // so missing values get good defaults
+       r_refdef.fog_density = atof(Cmd_Argv(1));
+       r_refdef.fog_red = atof(Cmd_Argv(2));
+       r_refdef.fog_green = atof(Cmd_Argv(3));
+       r_refdef.fog_blue = atof(Cmd_Argv(4));
+       r_refdef.fog_alpha = atof(Cmd_Argv(5));
+       r_refdef.fog_start = atof(Cmd_Argv(6));
+       r_refdef.fog_end = atof(Cmd_Argv(7));
+       r_refdef.fog_height = atof(Cmd_Argv(8));
+       r_refdef.fog_fadedepth = atof(Cmd_Argv(9));
+       strlcpy(r_refdef.fog_height_texturename, Cmd_Argv(10), sizeof(r_refdef.fog_height_texturename));
+}
+
+
 /*
 ====================
 CL_TimeRefresh_f
@@ -2082,8 +2156,7 @@ void CL_Locs_Save_f(void)
                Con_Printf("No level loaded!\n");
                return;
        }
-       FS_StripExtension(cl.worldmodel->name, locfilename, sizeof(locfilename));
-       strlcat(locfilename, ".loc", sizeof(locfilename));
+       dpsnprintf(locfilename, sizeof(locfilename), "%s.loc", cl.worldnamenoextension);
 
        outfile = FS_OpenRealFile(locfilename, "w", false);
        if (!outfile)
@@ -2160,14 +2233,12 @@ void CL_Locs_Reload_f(void)
        CL_Locs_Clear_f();
 
        // try maps/something.loc first (LordHavoc: where I think they should be)
-       FS_StripExtension(cl.worldmodel->name, locfilename, sizeof(locfilename));
-       strlcat(locfilename, ".loc", sizeof(locfilename));
+       dpsnprintf(locfilename, sizeof(locfilename), "%s.loc", cl.worldnamenoextension);
        filedata = (char *)FS_LoadFile(locfilename, cls.levelmempool, false, &filesize);
        if (!filedata)
        {
                // try proquake name as well (LordHavoc: I hate path mangling)
-               FS_StripExtension(va("locs/%s", FS_FileWithoutPath(cl.worldmodel->name)), locfilename, sizeof(locfilename));
-               strlcat(locfilename, ".loc", sizeof(locfilename));
+               dpsnprintf(locfilename, sizeof(locfilename), "locs/%s.loc", cl.worldbasename);
                filedata = (char *)FS_LoadFile(locfilename, cls.levelmempool, false, &filesize);
                if (!filedata)
                        return;
@@ -2301,6 +2372,7 @@ CL_Init
 */
 void CL_Init (void)
 {
+
        cls.levelmempool = Mem_AllocPool("client (per-level memory)", 0, NULL);
        cls.permanentmempool = Mem_AllocPool("client (long term memory)", 0, NULL);
 
@@ -2309,7 +2381,8 @@ void CL_Init (void)
        r_refdef.scene.maxentities = MAX_EDICTS + 256 + 512;
        r_refdef.scene.entities = (entity_render_t **)Mem_Alloc(cls.permanentmempool, sizeof(entity_render_t *) * r_refdef.scene.maxentities);
 
-       r_refdef.scene.maxtempentities = 4096; // FIXME: make this grow
+       // max temp entities
+       r_refdef.scene.maxtempentities = MAX_TEMPENTITIES;
        r_refdef.scene.tempentities = (entity_render_t *)Mem_Alloc(cls.permanentmempool, sizeof(entity_render_t) * r_refdef.scene.maxtempentities);
 
        CL_InitInput ();
@@ -2357,8 +2430,10 @@ void CL_Init (void)
 
        Cvar_RegisterVariable (&cl_autodemo);
        Cvar_RegisterVariable (&cl_autodemo_nameformat);
+       Cvar_RegisterVariable (&cl_autodemo_delete);
 
-       Cmd_AddCommand ("fog", CL_Fog_f, "set global fog parameters (density red green blue [alpha [mindist maxdist]])");
+       Cmd_AddCommand ("fog", CL_Fog_f, "set global fog parameters (density red green blue [alpha [mindist [maxdist [top [fadedepth]]]]])");
+       Cmd_AddCommand ("fog_heighttexture", CL_Fog_HeightTexture_f, "set global fog parameters (density red green blue alpha mindist maxdist top depth textures/mapname/fogheight.tga)");
 
        // LordHavoc: added pausedemo
        Cmd_AddCommand ("pausedemo", CL_PauseDemo_f, "pause demo playback (can also safely pause demo recording if using QUAKE, QUAKEDP or NEHAHRAMOVIE protocol, useful for making movies)");
@@ -2382,6 +2457,7 @@ void CL_Init (void)
        Cvar_RegisterVariable(&cl_dlights_decaybrightness);
 
        Cvar_RegisterVariable(&cl_prydoncursor);
+       Cvar_RegisterVariable(&cl_prydoncursor_notrace);
 
        Cvar_RegisterVariable(&cl_deathnoviewmodel);