]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_main.c
changed a lot of Host_Error calls to Con_Printf or Sys_Error according to severity
[xonotic/darkplaces.git] / cl_main.c
index c5caa7975899cf9eb02d999090067a988216b928..d638d18598e827bcfd0478a5df1321eeb41e87d5 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -30,7 +30,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 cvar_t cl_shownet = {0, "cl_shownet","0"};
 cvar_t cl_nolerp = {0, "cl_nolerp", "0"};
 
-cvar_t cl_itembobheight = {0, "cl_itembobheight", "8"};
+cvar_t cl_itembobheight = {0, "cl_itembobheight", "0"}; // try 8
 cvar_t cl_itembobspeed = {0, "cl_itembobspeed", "0.5"};
 
 cvar_t lookspring = {CVAR_SAVE, "lookspring","0"};
@@ -53,7 +53,7 @@ cvar_t cl_explosions_size_end = {CVAR_SAVE, "cl_explosions_size_end", "128"};
 cvar_t cl_explosions_lifetime = {CVAR_SAVE, "cl_explosions_lifetime", "0.5"};
 
 cvar_t cl_stainmaps = {CVAR_SAVE, "cl_stainmaps", "1"};
-cvar_t cl_stainmapsclearonload = {CVAR_SAVE, "cl_stainmapsclearonload", "0"};
+cvar_t cl_stainmaps_clearonload = {CVAR_SAVE, "cl_stainmaps_clearonload", "1"};
 
 cvar_t cl_beams_polygons = {CVAR_SAVE, "cl_beams_polygons", "1"};
 cvar_t cl_beams_relative = {CVAR_SAVE, "cl_beams_relative", "1"};
@@ -63,8 +63,12 @@ cvar_t cl_noplayershadow = {CVAR_SAVE, "cl_noplayershadow", "0"};
 
 cvar_t cl_prydoncursor = {0, "cl_prydoncursor", "0"};
 
-mempool_t *cl_refdef_mempool;
-mempool_t *cl_entities_mempool;
+vec3_t cl_playerstandmins;
+vec3_t cl_playerstandmaxs;
+vec3_t cl_playercrouchmins;
+vec3_t cl_playercrouchmaxs;
+
+mempool_t *cl_mempool;
 
 client_static_t        cls;
 client_state_t cl;
@@ -86,7 +90,7 @@ cl_effect_t *cl_effects;
 beam_t *cl_beams;
 dlight_t *cl_dlights;
 lightstyle_t *cl_lightstyle;
-entity_render_t **cl_brushmodel_entities;
+int *cl_brushmodel_entities;
 
 int cl_num_entities;
 int cl_num_static_entities;
@@ -103,16 +107,26 @@ void CL_ClearState(void)
 {
        int i;
 
+       if (cl_entities) Mem_Free(cl_entities);cl_entities = NULL;
+       if (cl_entities_active) Mem_Free(cl_entities_active);cl_entities_active = NULL;
+       if (cl_static_entities) Mem_Free(cl_static_entities);cl_static_entities = NULL;
+       if (cl_temp_entities) Mem_Free(cl_temp_entities);cl_temp_entities = NULL;
+       if (cl_effects) Mem_Free(cl_effects);cl_effects = NULL;
+       if (cl_beams) Mem_Free(cl_beams);cl_beams = NULL;
+       if (cl_dlights) Mem_Free(cl_dlights);cl_dlights = NULL;
+       if (cl_lightstyle) Mem_Free(cl_lightstyle);cl_lightstyle = NULL;
+       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.scores) Mem_Free(cl.scores);cl.scores = NULL;
+
        if (!sv.active)
                Host_ClearMemory ();
 
-       // note: this also gets rid of the entity database
-       Mem_EmptyPool(cl_entities_mempool);
-
 // wipe the entire cl structure
        memset (&cl, 0, sizeof(cl));
        // reset the view zoom interpolation
-       cl.viewzoomold = cl.viewzoomnew = 1;
+       cl.mviewzoom[0] = cl.mviewzoom[1] = 1;
 
        SZ_Clear (&cls.message);
 
@@ -122,7 +136,7 @@ void CL_ClearState(void)
        cl_num_brushmodel_entities = 0;
 
        // tweak these if the game runs out
-       cl_max_entities = MAX_EDICTS;
+       cl_max_entities = 256;
        cl_max_static_entities = 256;
        cl_max_temp_entities = 512;
        cl_max_effects = 256;
@@ -131,19 +145,15 @@ void CL_ClearState(void)
        cl_max_lightstyle = MAX_LIGHTSTYLES;
        cl_max_brushmodel_entities = MAX_EDICTS;
 
-       cl_entities = Mem_Alloc(cl_entities_mempool, cl_max_entities * sizeof(entity_t));
-       cl_entities_active = Mem_Alloc(cl_entities_mempool, cl_max_entities * sizeof(qbyte));
-       cl_static_entities = Mem_Alloc(cl_entities_mempool, cl_max_static_entities * sizeof(entity_t));
-       cl_temp_entities = Mem_Alloc(cl_entities_mempool, cl_max_temp_entities * sizeof(entity_t));
-       cl_effects = Mem_Alloc(cl_entities_mempool, cl_max_effects * sizeof(cl_effect_t));
-       cl_beams = Mem_Alloc(cl_entities_mempool, cl_max_beams * sizeof(beam_t));
-       cl_dlights = Mem_Alloc(cl_entities_mempool, cl_max_dlights * sizeof(dlight_t));
-       cl_lightstyle = Mem_Alloc(cl_entities_mempool, cl_max_lightstyle * sizeof(lightstyle_t));
-       cl_brushmodel_entities = Mem_Alloc(cl_entities_mempool, cl_max_brushmodel_entities * sizeof(entity_render_t *));
-
-       CL_Screen_NewMap();
-
-       CL_Particles_Clear();
+       cl_entities = Mem_Alloc(cl_mempool, cl_max_entities * sizeof(entity_t));
+       cl_entities_active = Mem_Alloc(cl_mempool, cl_max_brushmodel_entities * sizeof(qbyte));
+       cl_static_entities = Mem_Alloc(cl_mempool, cl_max_static_entities * sizeof(entity_t));
+       cl_temp_entities = Mem_Alloc(cl_mempool, cl_max_temp_entities * sizeof(entity_t));
+       cl_effects = Mem_Alloc(cl_mempool, cl_max_effects * sizeof(cl_effect_t));
+       cl_beams = Mem_Alloc(cl_mempool, cl_max_beams * sizeof(beam_t));
+       cl_dlights = Mem_Alloc(cl_mempool, cl_max_dlights * sizeof(dlight_t));
+       cl_lightstyle = Mem_Alloc(cl_mempool, cl_max_lightstyle * sizeof(lightstyle_t));
+       cl_brushmodel_entities = Mem_Alloc(cl_mempool, cl_max_brushmodel_entities * sizeof(int));
 
        // LordHavoc: have to set up the baseline info for alpha and other stuff
        for (i = 0;i < cl_max_entities;i++)
@@ -153,9 +163,51 @@ void CL_ClearState(void)
                cl_entities[i].state_current = defaultstate;
        }
 
+       if (gamemode == GAME_NEXUIZ)
+       {
+               VectorSet(cl_playerstandmins, -16, -16, -24);
+               VectorSet(cl_playerstandmaxs, 16, 16, 45);
+               VectorSet(cl_playercrouchmins, -16, -16, -24);
+               VectorSet(cl_playercrouchmaxs, 16, 16, 25);
+       }
+       else
+       {
+               VectorSet(cl_playerstandmins, -16, -16, -24);
+               VectorSet(cl_playerstandmaxs, 16, 16, 24);
+               VectorSet(cl_playercrouchmins, -16, -16, -24);
+               VectorSet(cl_playercrouchmaxs, 16, 16, 24);
+       }
+
+       CL_Screen_NewMap();
+       CL_Particles_Clear();
        CL_CGVM_Clear();
 }
 
+void CL_ExpandEntities(int num)
+{
+       int i, oldmaxentities;
+       entity_t *oldentities;
+       if (num >= cl_max_entities)
+       {
+               if (!cl_entities)
+                       Sys_Error("CL_ExpandEntities: cl_entities not initialized\n");
+               if (num >= MAX_EDICTS)
+                       Host_Error("CL_ExpandEntities: num %i >= %i\n", num, MAX_EDICTS);
+               oldmaxentities = cl_max_entities;
+               oldentities = cl_entities;
+               cl_max_entities = (num & ~255) + 256;
+               cl_entities = Mem_Alloc(cl_mempool, cl_max_entities * sizeof(entity_t));
+               memcpy(cl_entities, oldentities, oldmaxentities * sizeof(entity_t));
+               Mem_Free(oldentities);
+               for (i = oldmaxentities;i < cl_max_entities;i++)
+               {
+                       cl_entities[i].state_baseline = defaultstate;
+                       cl_entities[i].state_previous = defaultstate;
+                       cl_entities[i].state_current = defaultstate;
+               }
+       }
+}
+
 /*
 =====================
 CL_Disconnect
@@ -233,7 +285,7 @@ void CL_EstablishConnection(const char *host)
        CL_Disconnect();
        NetConn_ClientFrame();
        NetConn_ServerFrame();
-       
+
        if (LHNETADDRESS_FromString(&cls.connect_address, host, 26000) && (cls.connect_mysocket = NetConn_ChooseClientSocketForAddress(&cls.connect_address)))
        {
                cls.connect_trying = true;
@@ -281,7 +333,7 @@ static void CL_PrintEntities_f(void)
                        strcpy(name, "--no model--");
                for (j = strlen(name);j < 25;j++)
                        name[j] = ' ';
-               Con_Printf("%3i: %s:%04i (%5i %5i %5i) [%3i %3i %3i] %4.2f %5.3f\n", i, name, ent->render.frame, (int) ent->render.origin[0], (int) ent->render.origin[1], (int) ent->render.origin[2], (int) ent->render.angles[0] % 360, (int) ent->render.angles[1] % 360, (int) ent->render.angles[2] % 360, ent->render.scale, ent->render.alpha);
+               Con_Printf("%3i: %s:%4i (%5i %5i %5i) [%3i %3i %3i] %4.2f %5.3f\n", i, name, ent->render.frame, (int) ent->render.origin[0], (int) ent->render.origin[1], (int) ent->render.origin[2], (int) ent->render.angles[0] % 360, (int) ent->render.angles[1] % 360, (int) ent->render.angles[2] % 360, ent->render.scale, ent->render.alpha);
        }
 }
 
@@ -511,9 +563,10 @@ void CL_LinkNetworkEntity(entity_t *e)
        matrix4x4_t *matrix, blendmatrix, tempmatrix, matrix2;
        //matrix4x4_t dlightmatrix;
        int j, k, l, trailtype, temp;
-       float origin[3], angles[3], delta[3], lerp, dlightcolor[3], dlightradius, mins[3], maxs[3], v[3], v2[3], d;
+       float origin[3], angles[3], delta[3], lerp, dlightcolor[3], dlightradius, mins[3], maxs[3], v2[3], d;
        entity_t *t;
        model_t *model;
+       trace_t trace;
        //entity_persistent_t *p = &e->persistent;
        //entity_render_t *r = &e->render;
        if (e->persistent.linkframe != entitylinkframenumber)
@@ -534,14 +587,14 @@ void CL_LinkNetworkEntity(entity_t *e)
                        e->render.colormap = -1; // no special coloring
                e->render.skinnum = e->state_current.skin;
                VectorScale(e->state_current.colormod, (1.0f / 32.0f), e->render.colormod);
-               if (e->render.flags & RENDER_VIEWMODEL)
+               if (e->render.flags & RENDER_VIEWMODEL && !e->state_current.tagentity)
                {
                        if (!r_drawviewmodel.integer || chase_active.integer || envmap)
                                return;
                        if (cl.viewentity)
                                CL_LinkNetworkEntity(cl_entities + cl.viewentity);
                        matrix = &viewmodelmatrix;
-                       if (e == &cl.viewent && cl.viewentity >= 0 && cl.viewentity < MAX_EDICTS && cl_entities[cl.viewentity].state_current.active)
+                       if (e == &cl.viewent && cl_entities[cl.viewentity].state_current.active)
                        {
                                e->state_current.alpha = cl_entities[cl.viewentity].state_current.alpha;
                                e->state_current.effects = EF_NOSHADOW | (cl_entities[cl.viewentity].state_current.effects & (EF_ADDITIVE | EF_REFLECTIVE | EF_FULLBRIGHT | EF_NODEPTHTEST));
@@ -549,7 +602,11 @@ void CL_LinkNetworkEntity(entity_t *e)
                }
                else
                {
+                       // if the tag entity is currently impossible, skip it
+                       if (e->state_current.tagentity >= cl_num_entities)
+                               return;
                        t = cl_entities + e->state_current.tagentity;
+                       // if the tag entity is inactive, skip it
                        if (!t->state_current.active)
                                return;
                        // note: this can link to world
@@ -557,20 +614,21 @@ void CL_LinkNetworkEntity(entity_t *e)
                        // make relative to the entity
                        matrix = &t->render.matrix;
                        // some properties of the tag entity carry over
-                       e->render.flags |= t->render.flags & RENDER_EXTERIORMODEL;
+                       e->render.flags |= t->render.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 && (model = t->render.model) && e->state_current.tagindex <= t->render.model->alias.aliasnum_tags)
+                       if (e->state_current.tagentity && e->state_current.tagindex >= 1 && (model = t->render.model))
                        {
                                // blend the matrices
                                memset(&blendmatrix, 0, sizeof(blendmatrix));
                                for (j = 0;j < 4 && t->render.frameblend[j].lerp > 0;j++)
                                {
-                                       matrix = &t->render.model->alias.aliasdata_tags[t->render.frameblend[j].frame * t->render.model->alias.aliasnum_tags + (e->state_current.tagindex - 1)].matrix;
+                                       matrix4x4_t tagmatrix;
+                                       Mod_Alias_GetTagMatrix(model, t->render.frameblend[j].frame, e->state_current.tagindex - 1, &tagmatrix);
                                        d = t->render.frameblend[j].lerp;
                                        for (l = 0;l < 4;l++)
                                                for (k = 0;k < 4;k++)
-                                                       blendmatrix.m[l][k] += d * matrix->m[l][k];
+                                                       blendmatrix.m[l][k] += d * tagmatrix.m[l][k];
                                }
                                // concat the tag matrices onto the entity matrix
                                Matrix4x4_Concat(&tempmatrix, &t->render.matrix, &blendmatrix);
@@ -580,7 +638,15 @@ void CL_LinkNetworkEntity(entity_t *e)
                }
 
                // movement lerp
-               if (e->persistent.lerpdeltatime > 0 && (lerp = (cl.time - e->persistent.lerpstarttime) / e->persistent.lerpdeltatime) < 1)
+               // if it's the player entity, update according to client movement
+               if (e == cl_entities + cl.playerentity && cl.movement)
+               {
+                       lerp = (cl.time - cl.mtime[1]) / (cl.mtime[0] - cl.mtime[1]);
+                       lerp = bound(0, lerp, 1);
+                       VectorLerp(cl.movement_oldorigin, lerp, cl.movement_origin, origin);
+                       VectorSet(angles, 0, cl.viewangles[1], 0);
+               }
+               else if (e->persistent.lerpdeltatime > 0 && (lerp = (cl.time - e->persistent.lerpstarttime) / e->persistent.lerpdeltatime) < 1)
                {
                        // interpolate the origin and angles
                        VectorLerp(e->persistent.oldorigin, lerp, e->persistent.neworigin, origin);
@@ -612,9 +678,8 @@ void CL_LinkNetworkEntity(entity_t *e)
                                        origin[2] += (cos(cl.time * cl_itembobspeed.value * (2.0 * M_PI)) + 1.0) * 0.5 * cl_itembobheight.value;
                        }
                        // transfer certain model flags to effects
-                       if (e->render.model->flags2 & EF_FULLBRIGHT)
-                               e->render.effects |= EF_FULLBRIGHT;
-                       if (cl_prydoncursor.integer && (e->render.effects & EF_SELECTABLE) && cl.cmd.cursor_entitynumber == e - cl_entities)
+                       e->render.effects |= e->render.model->flags2 & (EF_FULLBRIGHT | EF_ADDITIVE);
+                       if (cl_prydoncursor.integer && (e->render.effects & EF_SELECTABLE) && cl.cmd.cursor_entitynumber == e->state_current.number)
                                VectorScale(e->render.colormod, 2, e->render.colormod);
                }
 
@@ -653,9 +718,19 @@ void CL_LinkNetworkEntity(entity_t *e)
                CL_BoundingBoxForEntity(&e->render);
 
                // handle effects now that we know where this entity is in the world...
-               origin[0] = e->render.matrix.m[0][3];
-               origin[1] = e->render.matrix.m[1][3];
-               origin[2] = e->render.matrix.m[2][3];
+               if (e->render.model && e->render.model->soundfromcenter)
+               {
+                       // bmodels are treated specially since their origin is usually '0 0 0'
+                       vec3_t o;
+                       VectorMAM(0.5f, e->render.model->normalmins, 0.5f, e->render.model->normalmaxs, o);
+                       Matrix4x4_Transform(&e->render.matrix, o, origin);
+               }
+               else
+               {
+                       origin[0] = e->render.matrix.m[0][3];
+                       origin[1] = e->render.matrix.m[1][3];
+                       origin[2] = e->render.matrix.m[2][3];
+               }
                trailtype = -1;
                dlightradius = 0;
                dlightcolor[0] = 0;
@@ -746,11 +821,11 @@ void CL_LinkNetworkEntity(entity_t *e)
                if (e->persistent.muzzleflash > 0)
                {
                        Matrix4x4_Transform(&e->render.matrix, muzzleflashorigin, v2);
-                       CL_TraceLine(origin, v2, v, NULL, true, NULL, SUPERCONTENTS_SOLID | SUPERCONTENTS_SKY);
+                       trace = CL_TraceBox(origin, vec3_origin, vec3_origin, v2, true, NULL, SUPERCONTENTS_SOLID | SUPERCONTENTS_SKY, false);
                        tempmatrix = e->render.matrix;
-                       tempmatrix.m[0][3] = v[0];
-                       tempmatrix.m[1][3] = v[1];
-                       tempmatrix.m[2][3] = v[2];
+                       tempmatrix.m[0][3] = trace.endpos[0];
+                       tempmatrix.m[1][3] = trace.endpos[1];
+                       tempmatrix.m[2][3] = trace.endpos[2];
                        CL_AllocDlight(NULL, &tempmatrix, 100, e->persistent.muzzleflash, e->persistent.muzzleflash, e->persistent.muzzleflash, 0, 0, 0, -1, true, 0, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
                        e->persistent.muzzleflash -= cl.frametime * 10;
                }
@@ -822,7 +897,7 @@ void CL_LinkNetworkEntity(entity_t *e)
                {
                        //dlightmatrix = e->render.matrix;
                        // hack to make glowing player light shine on their gun
-                       //if ((e - cl_entities) == cl.viewentity/* && !chase_active.integer*/)
+                       //if (e->state_current.number == cl.viewentity/* && !chase_active.integer*/)
                        //      dlightmatrix.m[2][3] += 30;
                        CL_AllocDlight(&e->render, &e->render.matrix, dlightradius, dlightcolor[0], dlightcolor[1], dlightcolor[2], 0, 0, 0, -1, true, 1, 0.25, 0.25, 1, 1, LIGHTFLAG_NORMALMODE | LIGHTFLAG_REALTIMEMODE);
                }
@@ -849,7 +924,7 @@ void CL_LinkNetworkEntity(entity_t *e)
                if (gamemode == GAME_TENEBRAE && e->render.model && e->render.model->type == mod_sprite)
                        e->render.effects |= EF_ADDITIVE;
                // player model is only shown with chase_active on
-               if (e - cl_entities == cl.viewentity)
+               if (e->state_current.number == cl.viewentity)
                        e->render.flags |= RENDER_EXTERIORMODEL;
                // transparent stuff can't be lit during the opaque stage
                if (e->render.effects & (EF_ADDITIVE | EF_NODEPTHTEST) || e->render.alpha < 1)
@@ -863,17 +938,15 @@ void CL_LinkNetworkEntity(entity_t *e)
                 && (!(e->render.flags & RENDER_EXTERIORMODEL) || (!cl.intermission && cl.protocol != PROTOCOL_NEHAHRAMOVIE && !cl_noplayershadow.integer)))
                        e->render.flags |= RENDER_SHADOW;
                // as soon as player is known we can call V_CalcRefDef
-               if ((e - cl_entities) == cl.viewentity)
+               if (e->state_current.number == cl.viewentity)
                        V_CalcRefdef();
                if (e->render.model && e->render.model->name[0] == '*' && e->render.model->TraceBox)
-                       cl_brushmodel_entities[cl_num_brushmodel_entities++] = &e->render;
+                       cl_brushmodel_entities[cl_num_brushmodel_entities++] = e->state_current.number;
                // 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.numentities < r_refdef.maxentities)
                        r_refdef.entities[r_refdef.numentities++] = &e->render;
-               if (cl_num_entities < e->state_current.number + 1)
-                       cl_num_entities = e->state_current.number + 1;
-               //if (cl.viewentity && e - cl_entities == cl.viewentity)
+               //if (cl.viewentity && e->state_current.number == cl.viewentity)
                //      Matrix4x4_Print(&e->render.matrix);
        }
 }
@@ -881,9 +954,7 @@ void CL_LinkNetworkEntity(entity_t *e)
 void CL_RelinkWorld(void)
 {
        entity_t *ent = &cl_entities[0];
-       if (cl_num_entities < 1)
-               cl_num_entities = 1;
-       cl_brushmodel_entities[cl_num_brushmodel_entities++] = &ent->render;
+       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);
@@ -959,10 +1030,11 @@ static void CL_RelinkNetworkEntities(void)
 
        // start on the entity after the world
        entitylinkframenumber++;
-       for (i = 1, ent = cl_entities + 1;i < MAX_EDICTS;i++, ent++)
+       for (i = 1;i < cl_num_entities;i++)
        {
                if (cl_entities_active[i])
                {
+                       ent = cl_entities + i;
                        if (ent->state_current.active)
                                CL_LinkNetworkEntity(ent);
                        else
@@ -1145,10 +1217,13 @@ void CL_LerpPlayer(float frac)
        int i;
        float d;
 
-       cl.viewzoom = cl.viewzoomold + frac * (cl.viewzoomnew - cl.viewzoomold);
-
+       cl.viewzoom = cl.mviewzoom[1] + frac * (cl.mviewzoom[0] - cl.mviewzoom[1]);
        for (i = 0;i < 3;i++)
+       {
+               cl.punchangle[i] = cl.mpunchangle[1][i] + frac * (cl.mpunchangle[0][i] - cl.mpunchangle[1][i]);
+               cl.punchvector[i] = cl.mpunchvector[1][i] + frac * (cl.mpunchvector[0][i] - cl.mpunchvector[1][i]);
                cl.velocity[i] = cl.mvelocity[1][i] + frac * (cl.mvelocity[0][i] - cl.mvelocity[1][i]);
+       }
 
        if (cls.demoplayback)
        {
@@ -1172,6 +1247,7 @@ CL_ReadFromServer
 Read all incoming data from the server
 ===============
 */
+extern void CL_ClientMovement_Replay();
 int CL_ReadFromServer(void)
 {
        CL_ReadDemoMessage();
@@ -1179,7 +1255,7 @@ int CL_ReadFromServer(void)
        r_refdef.time = cl.time;
        r_refdef.extraupdate = !r_speeds.integer;
        r_refdef.numentities = 0;
-       cl_num_entities = 0;
+       Matrix4x4_CreateIdentity(&r_refdef.viewentitymatrix);
        cl_num_brushmodel_entities = 0;
 
        if (cls.state == ca_connected && cls.signon == SIGNONS)
@@ -1192,6 +1268,7 @@ int CL_ReadFromServer(void)
                V_FadeViewFlashs();
 
                // relink network entities (note: this sets up the view!)
+               CL_ClientMovement_Replay();
                CL_RelinkNetworkEntities();
 
                // move particles
@@ -1219,11 +1296,9 @@ int CL_ReadFromServer(void)
 CL_SendCmd
 =================
 */
+void CL_UpdatePrydonCursor(void);
 void CL_SendCmd(void)
 {
-       if (cls.signon == SIGNONS)
-               CL_SendMove();
-
        if (cls.demoplayback)
        {
                SZ_Clear(&cls.message);
@@ -1300,6 +1375,20 @@ static void CL_TimeRefresh_f (void)
        Con_Printf("%f seconds (%f fps)\n", timedelta, 128/timedelta);
 }
 
+/*
+===========
+CL_Shutdown
+===========
+*/
+void CL_Shutdown (void)
+{
+       CL_CGVM_Shutdown();
+       CL_Particles_Shutdown();
+       CL_Parse_Shutdown();
+
+       Mem_FreePool (&cl_mempool);
+}
+
 /*
 =================
 CL_Init
@@ -1307,18 +1396,19 @@ CL_Init
 */
 void CL_Init (void)
 {
-       cl_entities_mempool = Mem_AllocPool("client entities", 0, NULL);
-       cl_refdef_mempool = Mem_AllocPool("refdef", 0, NULL);
+       cl_mempool = Mem_AllocPool("client", 0, NULL);
 
        memset(&r_refdef, 0, sizeof(r_refdef));
        // max entities sent to renderer per frame
        r_refdef.maxentities = MAX_EDICTS + 256 + 512;
-       r_refdef.entities = Mem_Alloc(cl_refdef_mempool, sizeof(entity_render_t *) * r_refdef.maxentities);
+       r_refdef.entities = Mem_Alloc(cl_mempool, sizeof(entity_render_t *) * r_refdef.maxentities);
        // 256k drawqueue buffer
        r_refdef.maxdrawqueuesize = 256 * 1024;
-       r_refdef.drawqueue = Mem_Alloc(cl_refdef_mempool, r_refdef.maxdrawqueuesize);
+       r_refdef.drawqueue = Mem_Alloc(cl_mempool, r_refdef.maxdrawqueuesize);
 
-       SZ_Alloc (&cls.message, 1024, "cls.message");
+       cls.message.data = cls.message_buf;
+       cls.message.maxsize = sizeof(cls.message_buf);
+       cls.message.cursize = 0;
 
        CL_InitInput ();
 
@@ -1367,7 +1457,7 @@ void CL_Init (void)
        Cvar_RegisterVariable(&cl_explosions_size_end);
        Cvar_RegisterVariable(&cl_explosions_lifetime);
        Cvar_RegisterVariable(&cl_stainmaps);
-       Cvar_RegisterVariable(&cl_stainmapsclearonload);
+       Cvar_RegisterVariable(&cl_stainmaps_clearonload);
        Cvar_RegisterVariable(&cl_beams_polygons);
        Cvar_RegisterVariable(&cl_beams_relative);
        Cvar_RegisterVariable(&cl_beams_lightatend);