]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_main.c
fixed bug that caused SV_SpawnServer to fail to send reconnect commands to clients...
[xonotic/darkplaces.git] / cl_main.c
index db35eaca553846d1bc21e15a70cdfbc108664e00..0ef8768fd7faa2c33ad6853d3c5b7b46e99b4de6 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -92,6 +92,8 @@ int cl_max_dlights;
 int cl_max_lightstyle;
 int cl_max_brushmodel_entities;
 int cl_activedlights;
+int cl_activeeffects;
+int cl_activebeams;
 
 entity_t *cl_entities;
 entity_t *cl_csqcentities;     //[515]: csqc
@@ -124,6 +126,7 @@ CL_ClearState
 void CL_ClearState(void)
 {
        int i;
+       entity_t *ent;
 
        if (cl_entities) Mem_Free(cl_entities);cl_entities = NULL;
        if (cl_csqcentities) Mem_Free(cl_csqcentities);cl_csqcentities = NULL;  //[515]: csqc
@@ -138,6 +141,7 @@ void CL_ClearState(void)
        if (cl_brushmodel_entities) Mem_Free(cl_brushmodel_entities);cl_brushmodel_entities = NULL;
        if (cl.entitydatabase) EntityFrame_FreeDatabase(cl.entitydatabase);cl.entitydatabase = NULL;
        if (cl.entitydatabase4) EntityFrame4_FreeDatabase(cl.entitydatabase4);cl.entitydatabase4 = NULL;
+       if (cl.entitydatabaseqw) EntityFrameQW_FreeDatabase(cl.entitydatabaseqw);cl.entitydatabaseqw = NULL;
        if (cl.scores) Mem_Free(cl.scores);cl.scores = NULL;
 
        if (!sv.active)
@@ -145,6 +149,9 @@ void CL_ClearState(void)
 
 // wipe the entire cl structure
        memset (&cl, 0, sizeof(cl));
+
+       S_StopAllSounds();
+
        // reset the view zoom interpolation
        cl.mviewzoom[0] = cl.mviewzoom[1] = 1;
 
@@ -165,6 +172,8 @@ void CL_ClearState(void)
        cl_max_lightstyle = MAX_LIGHTSTYLES;
        cl_max_brushmodel_entities = MAX_EDICTS;
        cl_activedlights = 0;
+       cl_activeeffects = 0;
+       cl_activebeams = 0;
 
        cl_entities = (entity_t *)Mem_Alloc(cl_mempool, cl_max_entities * sizeof(entity_t));
        cl_csqcentities = (entity_t *)Mem_Alloc(cl_mempool, cl_max_csqcentities * sizeof(entity_t));    //[515]: csqc
@@ -213,6 +222,27 @@ void CL_ClearState(void)
                VectorSet(cl_playercrouchmaxs, 16, 16, 24);
        }
 
+       // disable until we get textures for it
+       R_ResetSkyBox();
+
+       ent = &cl_entities[0];
+       // entire entity array was cleared, so just fill in a few fields
+       ent->state_current.active = true;
+       ent->render.model = cl.worldmodel = NULL; // no world model yet
+       ent->render.scale = 1; // some of the renderer still relies on scale
+       ent->render.alpha = 1;
+       ent->render.colormap = -1; // no special coloring
+       ent->render.flags = RENDER_SHADOW | RENDER_LIGHT;
+       Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, 0, 0, 0, 0, 0, 0, 1);
+       Matrix4x4_Invert_Simple(&ent->render.inversematrix, &ent->render.matrix);
+       CL_BoundingBoxForEntity(&ent->render);
+
+       // noclip is turned off at start
+       noclip_anglehack = false;
+
+       // mark all frames invalid for delta
+       memset(cl.qw_deltasequence, -1, sizeof(cl.qw_deltasequence));
+
        CL_Screen_NewMap();
        CL_Particles_Clear();
        CL_CGVM_Clear();
@@ -307,13 +337,22 @@ void CL_Disconnect(void)
                if (cls.demorecording)
                        CL_Stop_f();
 
-               // send clc_disconnect 3 times to improve chances of server receiving
-               // it (but it still fails sometimes)
-               Con_DPrint("Sending clc_disconnect\n");
+               // send disconnect message 3 times to improve chances of server
+               // receiving it (but it still fails sometimes)
                memset(&buf, 0, sizeof(buf));
                buf.data = bufdata;
                buf.maxsize = sizeof(bufdata);
-               MSG_WriteByte(&buf, clc_disconnect);
+               if (cls.protocol == PROTOCOL_QUAKEWORLD)
+               {
+                       Con_DPrint("Sending drop command\n");
+                       MSG_WriteByte(&buf, qw_clc_stringcmd);
+                       MSG_WriteString(&buf, "drop");
+               }
+               else
+               {
+                       Con_DPrint("Sending clc_disconnect\n");
+                       MSG_WriteByte(&buf, clc_disconnect);
+               }
                NetConn_SendUnreliableMessage(cls.netcon, &buf, cls.protocol);
                NetConn_SendUnreliableMessage(cls.netcon, &buf, cls.protocol);
                NetConn_SendUnreliableMessage(cls.netcon, &buf, cls.protocol);
@@ -541,6 +580,7 @@ void CL_Effect(vec3_t org, int modelindex, int startframe, int framecount, float
                e->frame = 0;
                e->frame1time = cl.time;
                e->frame2time = cl.time;
+               cl_activeeffects = max(cl_activeeffects, i + 1);
                break;
        }
 }
@@ -723,7 +763,7 @@ void CL_AddQWCTFFlagModel(entity_t *player, int skin)
        VectorSet(flag->render.colormod, 1, 1, 1);
        // attach the flag to the player matrix
        Matrix4x4_CreateFromQuakeEntity(&flagmatrix, -f, -22, 0, 0, 0, -45, 1);
-       Matrix4x4_Concat(&flag->render.matrix, &flagmatrix, &player->render.matrix);
+       Matrix4x4_Concat(&flag->render.matrix, &player->render.matrix, &flagmatrix);
        Matrix4x4_Invert_Simple(&flag->render.inversematrix, &flag->render.matrix);
        R_LerpAnimation(&flag->render);
        CL_BoundingBoxForEntity(&flag->render);
@@ -1200,8 +1240,8 @@ void CL_RelinkWorld(void)
        entity_t *ent = &cl_entities[0];
        cl_brushmodel_entities[cl_num_brushmodel_entities++] = 0;
        // FIXME: this should be done at load
-       Matrix4x4_CreateIdentity(&ent->render.matrix);
-       Matrix4x4_CreateIdentity(&ent->render.inversematrix);
+       ent->render.matrix = identitymatrix;
+       ent->render.inversematrix = identitymatrix;
        R_LerpAnimation(&ent->render);
        CL_BoundingBoxForEntity(&ent->render);
        ent->render.flags = RENDER_SHADOW;
@@ -1219,8 +1259,8 @@ void CL_RelinkCSQCWorld(void)     //[515]: csqc
                return;
 //     cl_brushmodel_entities[cl_num_brushmodel_entities++] = 0;
        // FIXME: this should be done at load
-       Matrix4x4_CreateIdentity(&ent->render.matrix);
-       Matrix4x4_CreateIdentity(&ent->render.inversematrix);
+       ent->render.matrix = identitymatrix;
+       ent->render.inversematrix = identitymatrix;
        R_LerpAnimation(&ent->render);
        CL_BoundingBoxForEntity(&ent->render);
        ent->render.flags = RENDER_SHADOW;
@@ -1343,7 +1383,7 @@ static void CL_RelinkEffects(void)
        entity_t *ent;
        float frame;
 
-       for (i = 0, e = cl_effects;i < cl_max_effects;i++, e++)
+       for (i = 0, e = cl_effects;i < cl_activeeffects;i++, e++)
        {
                if (e->active)
                {
@@ -1352,6 +1392,8 @@ static void CL_RelinkEffects(void)
                        if (intframe < 0 || intframe >= e->endframe)
                        {
                                memset(e, 0, sizeof(*e));
+                               while (cl_activeeffects > 0 && !cl_effects[cl_activeeffects - 1].active)
+                                       cl_activeeffects--;
                                continue;
                        }
 
@@ -1405,10 +1447,17 @@ void CL_RelinkBeams(void)
        float forward;
        matrix4x4_t tempmatrix;
 
-       for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
+       while (cl_activebeams > 0 && !cl_beams[cl_activebeams - 1].model)
+               cl_activeeffects--;
+       for (i = 0, b = cl_beams;i < cl_activebeams;i++, b++)
        {
-               if (!b->model || b->endtime < cl.time)
+               if (!b->model)
+                       continue;
+               if (b->endtime < cl.time)
+               {
+                       b->model = NULL;
                        continue;
+               }
 
                // if coming from the player, update the start position
                //if (b->entity == cl.viewentity)
@@ -1576,7 +1625,7 @@ int CL_ReadFromServer(void)
        r_refdef.time = cl.time;
        r_refdef.extraupdate = !r_speeds.integer;
        r_refdef.numentities = 0;
-       Matrix4x4_CreateIdentity(&r_refdef.viewentitymatrix);
+       r_refdef.viewentitymatrix = identitymatrix;
        cl_num_brushmodel_entities = 0;
 
        if (cls.state == ca_connected && cls.signon == SIGNONS)
@@ -1604,6 +1653,7 @@ int CL_ReadFromServer(void)
                        CL_RelinkStaticEntities();
                        CL_RelinkBeams();
                        CL_RelinkEffects();
+                       CL_RelinkQWNails();
                }
                else
                        csqc_frame = true;