]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_main.c
added CVAR_SAVE and CVAR_NOTIFY flags to cvar_t structure (at the beginning), updated...
[xonotic/darkplaces.git] / cl_main.c
index 5f3d6cb027b2fa9f1282ad268aade2d6edbf2ebe..0341b9db388756c42feb337d61e1ecfebaaebf96 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 See the GNU General Public License for more details.
 
@@ -25,27 +25,27 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 // references them even when on a unix system.
 
 // these two are not intended to be set directly
-cvar_t cl_name = {"_cl_name", "player", true};
-cvar_t cl_color = {"_cl_color", "0", true};
-cvar_t cl_pmodel = {"_cl_pmodel", "0", true};
+cvar_t cl_name = {CVAR_SAVE, "_cl_name", "player"};
+cvar_t cl_color = {CVAR_SAVE, "_cl_color", "0"};
+cvar_t cl_pmodel = {CVAR_SAVE, "_cl_pmodel", "0"};
 
-cvar_t cl_shownet = {"cl_shownet","0"};        // can be 0, 1, or 2
-cvar_t cl_nolerp = {"cl_nolerp","0"};
+cvar_t cl_shownet = {0, "cl_shownet","0"};
+cvar_t cl_nolerp = {0, "cl_nolerp", "0"};
 
-cvar_t lookspring = {"lookspring","0", true};
-cvar_t lookstrafe = {"lookstrafe","0", true};
-cvar_t sensitivity = {"sensitivity","3", true};
+cvar_t lookspring = {CVAR_SAVE, "lookspring","0"};
+cvar_t lookstrafe = {CVAR_SAVE, "lookstrafe","0"};
+cvar_t sensitivity = {CVAR_SAVE, "sensitivity","3", 1, 30};
 
-cvar_t m_pitch = {"m_pitch","0.022", true};
-cvar_t m_yaw = {"m_yaw","0.022", true};
-cvar_t m_forward = {"m_forward","1", true};
-cvar_t m_side = {"m_side","0.8", true};
+cvar_t m_pitch = {CVAR_SAVE, "m_pitch","0.022"};
+cvar_t m_yaw = {CVAR_SAVE, "m_yaw","0.022"};
+cvar_t m_forward = {CVAR_SAVE, "m_forward","1"};
+cvar_t m_side = {CVAR_SAVE, "m_side","0.8"};
 
+cvar_t freelook = {CVAR_SAVE, "freelook", "1"};
 
 client_static_t        cls;
 client_state_t cl;
 // FIXME: put these on hunk?
-//efrag_t                      cl_efrags[MAX_EFRAGS];
 entity_t               cl_entities[MAX_EDICTS];
 entity_t               cl_static_entities[MAX_STATIC_ENTITIES];
 lightstyle_t   cl_lightstyle[MAX_LIGHTSTYLES];
@@ -73,7 +73,6 @@ void CL_ClearState (void)
        SZ_Clear (&cls.message);
 
 // clear other arrays  
-//     memset (cl_efrags, 0, sizeof(cl_efrags));
        memset (cl_entities, 0, sizeof(cl_entities));
        memset (cl_dlights, 0, sizeof(cl_dlights));
        memset (cl_lightstyle, 0, sizeof(cl_lightstyle));
@@ -82,20 +81,10 @@ void CL_ClearState (void)
        // LordHavoc: have to set up the baseline info for alpha and other stuff
        for (i = 0;i < MAX_EDICTS;i++)
        {
-               cl_entities[i].state_baseline.alpha = 255;
-               cl_entities[i].state_baseline.scale = 16;
-               cl_entities[i].state_baseline.glowsize = 0;
-               cl_entities[i].state_baseline.glowcolor = 254;
-               cl_entities[i].state_baseline.colormod = 255;
+               ClearStateToDefault(&cl_entities[i].state_baseline);
+               ClearStateToDefault(&cl_entities[i].state_previous);
+               ClearStateToDefault(&cl_entities[i].state_current);
        }
-
-////
-//// allocate the efrags and chain together into a free list
-////
-//     cl.free_efrags = cl_efrags;
-//     for (i=0 ; i<MAX_EFRAGS-1 ; i++)
-//             cl.free_efrags[i].entnext = &cl.free_efrags[i+1];
-//     cl.free_efrags[i].entnext = NULL;
 }
 
 /*
@@ -388,13 +377,13 @@ float     CL_LerpPoint (void)
                f = 0.1;
        }
        frac = (cl.time - cl.mtime[1]) / f;
-//Con_Printf ("frac: %f\n",frac);
+//     Con_Printf ("frac: %f\n",frac);
        if (frac < 0)
        {
                if (frac < -0.01)
                {
                        cl.time = cl.mtime[1];
-//                             Con_Printf ("low frac\n");
+//                     Con_Printf ("low frac\n");
                }
                frac = 0;
        }
@@ -403,7 +392,7 @@ float       CL_LerpPoint (void)
                if (frac > 1.01)
                {
                        cl.time = cl.mtime[0];
-//                             Con_Printf ("high frac\n");
+//                     Con_Printf ("high frac\n");
                }
                frac = 1;
        }
@@ -431,7 +420,7 @@ float CL_EntityLerpPoint (entity_t *ent)
        return bound(0, f, 1);
 }
 
-void CL_RelinkStaticEntities()
+void CL_RelinkStaticEntities(void)
 {
        entity_t *ent, *endent;
        if (cl.num_statics > MAX_VISEDICTS)
@@ -452,12 +441,9 @@ void R_RocketTrail2 (vec3_t start, vec3_t end, int color, entity_t *ent);
 void CL_RelinkEntities (void)
 {
        entity_t        *ent;
-       int                     i, j;
-       float           frac, f, d;
-       vec3_t          delta;
-       float           bobjrotate;
-//     float           bobjoffset;
-       vec3_t          oldorg;
+       int                     i, j, glowcolor, effects;
+       float           frac, f, d, bobjrotate/*, bobjoffset*/, dlightradius, glowsize;
+       vec3_t          oldorg, delta, dlightcolor;
 
 // determine partial update time       
        frac = CL_LerpPoint ();
@@ -474,7 +460,7 @@ void CL_RelinkEntities (void)
 
        if (cls.demoplayback)
        {
-       // interpolate the angles       
+       // interpolate the angles
                for (j = 0;j < 3;j++)
                {
                        d = cl.mviewangles[0][j] - cl.mviewangles[1][j];
@@ -543,7 +529,7 @@ void CL_RelinkEntities (void)
                }
 
                ent->render.flags = ent->state_current.flags;
-               ent->render.effects = ent->state_current.effects;
+               ent->render.effects = effects = ent->state_current.effects;
                ent->render.model = cl.model_precache[ent->state_current.modelindex];
                ent->render.frame = ent->state_current.frame;
                if (cl.scores == NULL || !ent->state_current.colormap)
@@ -553,18 +539,23 @@ void CL_RelinkEntities (void)
                ent->render.skinnum = ent->state_current.skin;
                ent->render.alpha = ent->state_current.alpha * (1.0f / 255.0f); // FIXME: interpolate?
                ent->render.scale = ent->state_current.scale * (1.0f / 16.0f); // FIXME: interpolate?
-               ent->render.glowsize = ent->state_current.glowsize * 4.0f; // FIXME: interpolate?
-               ent->render.glowcolor = ent->state_current.glowcolor;
+               glowsize = ent->state_current.glowsize * 4.0f; // FIXME: interpolate?
+               glowcolor = ent->state_current.glowcolor;
                ent->render.colormod[0] = (float) ((ent->state_current.colormod >> 5) & 7) * (1.0f / 7.0f);
                ent->render.colormod[1] = (float) ((ent->state_current.colormod >> 2) & 7) * (1.0f / 7.0f);
                ent->render.colormod[2] = (float) (ent->state_current.colormod & 3) * (1.0f / 3.0f);
 
+               dlightradius = 0;
+               dlightcolor[0] = 0;
+               dlightcolor[1] = 0;
+               dlightcolor[2] = 0;
+
                // LordHavoc: if the entity has no effects, don't check each
-               if (ent->render.effects)
+               if (effects)
                {
-                       if (ent->render.effects & EF_BRIGHTFIELD)
+                       if (effects & EF_BRIGHTFIELD)
                                R_EntityParticles (ent);
-                       if (ent->render.effects & EF_MUZZLEFLASH)
+                       if (effects & EF_MUZZLEFLASH)
                        {
                                vec3_t v;
 
@@ -574,23 +565,34 @@ void CL_RelinkEntities (void)
                                v[1] = v[1] * 18 + ent->render.origin[1];
                                v[2] = v[2] * 18 + ent->render.origin[2] + 16;
 
-                               CL_AllocDlight (ent, v, 100, 1, 1, 1, 0, 0.1);
+                               CL_AllocDlight (NULL, v, 100, 1, 1, 1, 0, 0.1);
+                       }
+                       if (effects & EF_DIMLIGHT)
+                       {
+                               dlightcolor[0] += 200.0f;
+                               dlightcolor[1] += 200.0f;
+                               dlightcolor[2] += 200.0f;
+                       }
+                       if (effects & EF_BRIGHTLIGHT)
+                       {
+                               dlightcolor[0] += 400.0f;
+                               dlightcolor[1] += 400.0f;
+                               dlightcolor[2] += 400.0f;
                        }
-                       if (ent->render.effects & EF_BRIGHTLIGHT)
-                               CL_AllocDlight (ent, ent->render.origin, 400, 1, 1, 1, 0, 0);
-                       if (ent->render.effects & EF_DIMLIGHT)
-                               CL_AllocDlight (ent, ent->render.origin, 200, 1, 1, 1, 0, 0);
                        // LordHavoc: added EF_RED and EF_BLUE
-                       if (ent->render.effects & EF_RED) // red
-                       {                       
-                               if (ent->render.effects & EF_BLUE) // magenta
-                                       CL_AllocDlight (ent, ent->render.origin, 200, 1.0f, 0.2f, 1.0f, 0, 0);
-                               else // red
-                                       CL_AllocDlight (ent, ent->render.origin, 200, 1.0f, 0.1f, 0.1f, 0, 0);
+                       if (effects & EF_RED) // red
+                       {
+                               dlightcolor[0] += 200.0f;
+                               dlightcolor[1] +=  20.0f;
+                               dlightcolor[2] +=  20.0f;
                        }
-                       else if (ent->render.effects & EF_BLUE) // blue
-                               CL_AllocDlight (ent, ent->render.origin, 200, 0.1f, 0.1f, 1.0f, 0, 0);
-                       else if (ent->render.effects & EF_FLAME)
+                       if (effects & EF_BLUE) // blue
+                       {
+                               dlightcolor[0] +=  20.0f;
+                               dlightcolor[1] +=  20.0f;
+                               dlightcolor[2] += 200.0f;
+                       }
+                       else if (effects & EF_FLAME)
                        {
                                if (ent->render.model)
                                {
@@ -602,7 +604,10 @@ void CL_RelinkEntities (void)
                                        temp = (int) (cl.time * 300) - (int) (cl.oldtime * 300);
                                        R_FlameCube(mins, maxs, temp);
                                }
-                               CL_AllocDlight (ent, ent->render.origin, lhrandom(200, 250), 1.0f, 0.7f, 0.3f, 0, 0);
+                               d = lhrandom(200, 250);
+                               dlightcolor[0] += d * 1.0f;
+                               dlightcolor[1] += d * 0.7f;
+                               dlightcolor[2] += d * 0.3f;
                        }
                }
 
@@ -628,7 +633,9 @@ void CL_RelinkEntities (void)
                                else if (ent->render.model->flags & EF_ROCKET)
                                {
                                        R_RocketTrail (oldorg, ent->render.origin, 0, ent);
-                                       CL_AllocDlight (ent, ent->render.origin, 200, 1.0f, 0.8f, 0.4f, 0, 0);
+                                       dlightcolor[0] += 200.0f;
+                                       dlightcolor[1] += 160.0f;
+                                       dlightcolor[2] +=  80.0f;
                                }
                                else if (ent->render.model->flags & EF_GRENADE)
                                {
@@ -641,20 +648,43 @@ void CL_RelinkEntities (void)
                                        R_RocketTrail (oldorg, ent->render.origin, 6, ent);
                        }
                }
-               if (ent->render.glowsize) // LordHavoc: customizable glow
+               // LordHavoc: customizable glow
+               if (glowsize)
                {
-                       byte *tempcolor = (byte *)&d_8to24table[ent->render.glowcolor];
-                       CL_AllocDlight (ent, ent->render.origin, ent->render.glowsize, tempcolor[0]*(1.0/255.0), tempcolor[1]*(1.0/255.0), tempcolor[2]*(1.0/255.0), 0, 0);
+                       byte *tempcolor = (byte *)&d_8to24table[glowcolor];
+                       dlightcolor[0] += glowsize * tempcolor[0] * (1.0f / 255.0f);
+                       dlightcolor[1] += glowsize * tempcolor[1] * (1.0f / 255.0f);
+                       dlightcolor[2] += glowsize * tempcolor[2] * (1.0f / 255.0f);
                }
-               if (ent->render.flags & RENDER_GLOWTRAIL) // LordHavoc: customizable glow and trail
-                       R_RocketTrail2 (oldorg, ent->render.origin, ent->render.glowcolor, ent);
+               // LordHavoc: customizable trail
+               if (ent->render.flags & RENDER_GLOWTRAIL)
+                       R_RocketTrail2 (oldorg, ent->render.origin, glowcolor, ent);
 
-               if (i == cl.viewentity && !chase_active.value)
-                       continue;
+               if (dlightcolor[0] || dlightcolor[1] || dlightcolor[2])
+               {
+                       vec3_t vec;
+                       dlightradius = VectorLength(dlightcolor);
+                       d = 1.0f / dlightradius;
+                       VectorCopy(ent->render.origin, vec);
+                       if (i == cl.viewentity && !chase_active.value)
+                               vec[2] += 30;
+                       CL_AllocDlight (ent, vec, dlightradius, dlightcolor[0] * d, dlightcolor[1] * d, dlightcolor[2] * d, 0, 0);
+               }
+
+               if (chase_active.value)
+               {
+                       if (ent->render.flags & RENDER_VIEWMODEL)
+                               continue;
+               }
+               else
+               {
+                       if (i == cl.viewentity || (ent->render.flags & RENDER_EXTERIORMODEL))
+                               continue;
+               }
 
                if (ent->render.model == NULL)
                        continue;
-               if (ent->render.effects & EF_NODRAW)
+               if (effects & EF_NODRAW)
                        continue;
                if (cl_numvisedicts < MAX_VISEDICTS)
                        cl_visedicts[cl_numvisedicts++] = ent;
@@ -663,9 +693,6 @@ void CL_RelinkEntities (void)
 }
 
 
-// used by cl_shownet
-int netshown;
-
 /*
 ===============
 CL_ReadFromServer
@@ -675,7 +702,7 @@ Read all incoming data from the server
 */
 int CL_ReadFromServer (void)
 {
-       int             ret;
+       int ret, netshown;
 
        cl.oldtime = cl.time;
        cl.time += cl.frametime;
@@ -690,8 +717,13 @@ int CL_ReadFromServer (void)
                        break;
                
                cl.last_received_message = realtime;
+
+               if (cl_shownet.value)
+                       netshown = true;
+
                CL_ParseServerMessage ();
-       } while (ret && cls.state == ca_connected);
+       }
+       while (ret && cls.state == ca_connected);
        
        if (netshown)
                Con_Printf ("\n");
@@ -722,7 +754,7 @@ void CL_SendCmd (void)
        {
        // get basic movement from keyboard
                CL_BaseMove (&cmd);
-       
+
        // allow mice or other external controllers to add to the move
                IN_Move (&cmd);
        
@@ -813,8 +845,6 @@ void CL_Fog_f (void)
        fog_blue = atof(Cmd_Argv(4));
 }
 
-cvar_t demo_nehahra = {"demo_nehahra", "0"};
-
 /*
 =================
 CL_Init
@@ -846,6 +876,7 @@ void CL_Init (void)
        Cvar_RegisterVariable (&lookspring);
        Cvar_RegisterVariable (&lookstrafe);
        Cvar_RegisterVariable (&sensitivity);
+       Cvar_RegisterVariable (&freelook);
 
        Cvar_RegisterVariable (&m_pitch);
        Cvar_RegisterVariable (&m_yaw);
@@ -855,6 +886,7 @@ void CL_Init (void)
 //     Cvar_RegisterVariable (&cl_autofire);
        
        Cmd_AddCommand ("entities", CL_PrintEntities_f);
+       Cmd_AddCommand ("bitprofile", CL_BitProfile_f);
        Cmd_AddCommand ("disconnect", CL_Disconnect_f);
        Cmd_AddCommand ("record", CL_Record_f);
        Cmd_AddCommand ("stop", CL_Stop_f);
@@ -867,9 +899,6 @@ void CL_Init (void)
        Cmd_AddCommand ("pausedemo", CL_PauseDemo_f);
        // LordHavoc: added pmodel command (like name, etc, only intended for Nehahra)
        Cmd_AddCommand ("pmodel", CL_PModel_f);
-       // LordHavoc: added demo_nehahra cvar
-       Cvar_RegisterVariable (&demo_nehahra);
-       if (nehahra)
-               Cvar_SetValue("demo_nehahra", 1);
-}
 
+       CL_Parse_Init();
+}